﻿#include <sstream>
#include "Windows.h"
#include "Commdlg.h"
#include "zyPropertyGrid.h"
#include "zyColorDialog.h"
#include "zyTabControl.h"
#include "zyListView.h"
#include "zyStatic.h"
#include "zyFontDialog.h"
//#include "../3rdparty/pugixml/pugixml.hpp"
BlackMoonUI::zyPropertyGrid::zyPropertyGrid()
{
	SetMember(L"this", (LONG_PTR)this);
	m_obj->setWndProc(zyPropertyGrid_WndProc);
	m_obj->setChildWndProc(zyPropertyGrid_ChildWndProc);
	m_obj->setDestroy(zyPropertyGrid_Destroy);
	setType(zyType_PropertyGrid);
}
BlackMoonUI::zyPropertyGrid::~zyPropertyGrid()
{

}
void WINAPI BlackMoonUI::zyPropertyGrid::zyPropertyGrid_Destroy(zyObject* obj)
{
	zyPropertyGrid* zyb = (zyPropertyGrid*)obj->getPtrData(L"this");
	zyb->OnNCDestroy();
	zyCtrol::zyCtrol_Destroy(obj);
}
LRESULT WINAPI BlackMoonUI::zyPropertyGrid::zyPropertyGrid_ChildWndProc(zyObject* obj, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL* bHandle)
{
	if (message == WM_NOTIFY) {
		NMHDR* nm = reinterpret_cast<NMHDR*>(lParam);
		switch (nm->code) {
		case NM_CUSTOMDRAW: {
			NMLVCUSTOMDRAW* nmlvCust = reinterpret_cast<NMLVCUSTOMDRAW*>(lParam);
			switch (nmlvCust->nmcd.dwDrawStage) {
			case CDDS_PREPAINT:
				*bHandle = TRUE;
				return CDRF_NOTIFYITEMDRAW;
			case CDDS_ITEMPREPAINT: {			
				PropertyGrid_item* pItem = reinterpret_cast<PropertyGrid_item*>(nmlvCust->nmcd.lItemlParam);
				if (pItem) {
					zyPropertyGrid* p = reinterpret_cast<zyPropertyGrid*>(obj->getPtrData(L"this"));
					p->propertyItem_OnDraw(pItem, lParam);
				}
				*bHandle = TRUE;
				return CDRF_SKIPDEFAULT;
			}
			default:
				*bHandle = TRUE;
				return CDRF_DODEFAULT;
			}
		}
		case LVN_ITEMCHANGED: {
			NMLISTVIEW* nmlv = reinterpret_cast<NMLISTVIEW*>(lParam);
			if ((nmlv->uNewState & LVIS_SELECTED) == LVIS_SELECTED) {
				PropertyGrid_item* pItem = reinterpret_cast<PropertyGrid_item*>(nmlv->lParam);
				if (pItem && pItem->Type != 属性类型_分组) { // 跳过分组项
					zyPropertyGrid* p = reinterpret_cast<zyPropertyGrid*>(obj->getPtrData(L"this"));
					p->propertyItem_BeginEdit(pItem, nmlv->iItem);
				}
			}
			TRegEvent* evtPtr = obj->getRegEvent(L"OnItemChange");
			if (evtPtr)
				evtPtr->handler<int>(nm->hwndFrom, reinterpret_cast<PropertyGrid_item*>(nmlv->lParam));
			break;
		}
		/*case LVN_DELETEITEM: {
			zyPropertyGrid* p = reinterpret_cast<zyPropertyGrid*>(obj->getPtrData(L"this"));
			p->zyPropretyGrid_HideAll();
			break;
		}*/
		case NM_DBLCLK: {
			if (GetParent(nm->hwndFrom) == hWnd) {
				NMITEMACTIVATE* nmia = reinterpret_cast<NMITEMACTIVATE*>(lParam);
				LVITEM item = { 0 };
				item.mask = LVIF_PARAM;
				item.iItem = nmia->iItem;
				SendMessage(nm->hwndFrom, LVM_GETITEMW, 0, (LPARAM)&item);
				PropertyGrid_item* pItem = reinterpret_cast<PropertyGrid_item*>(item.lParam);
				TRegEvent* evtPtr = obj->getRegEvent(L"OnDBClick");
				if (evtPtr)
					evtPtr->handler<int>(nm->hwndFrom, pItem, nmia->iSubItem);
			}
			break;
		}
		default:
			break;
		}
	}
	return zyCtrol::zyCtrol_ChildWndProc(obj, hWnd, message, wParam, lParam, bHandle);
}
LRESULT WINAPI BlackMoonUI::zyPropertyGrid::zyPropertyGrid_WndProc(zyObject* obj, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL* bHandle)
{
	if (uMsg == WM_NOTIFY) {
		NMHDR* nmh = reinterpret_cast<NMHDR*>(lParam);
		HWND hHeader = ListView_GetHeader(hWnd);
		if (nmh->hwndFrom == hHeader && nmh->code == NM_CUSTOMDRAW) {
			NMCUSTOMDRAW* pCD = reinterpret_cast<NMCUSTOMDRAW*>(lParam);
			switch (pCD->dwDrawStage) {
			case CDDS_PREPAINT:
				*bHandle = TRUE;
				return CDRF_NOTIFYITEMDRAW; // 通知每个表头项的绘制
			case CDDS_ITEMPREPAINT: {
				// 获取当前表头项的索引和矩形
				int iItem = static_cast<int>(pCD->dwItemSpec);
				RECT rcItem = {0};
				Header_GetItemRect(hHeader, iItem, &rcItem);

				// 填充背景色
				HBRUSH hBrush = CreateSolidBrush(15790320);
				FillRect(pCD->hdc, &rcItem, hBrush);
				DeleteObject(hBrush);

				// 设置文本颜色和字体
				SetTextColor(pCD->hdc, RGB(0, 0, 0));
				SetBkMode(pCD->hdc, TRANSPARENT);
				HFONT hFont = (HFONT)SendMessage(hHeader, WM_GETFONT, 0, 0);
				SelectObject(pCD->hdc, hFont);

				// 获取表头项文本
				TCHAR szText[256];
				HD_ITEM hdi = { HDI_TEXT | HDI_FORMAT };
				hdi.pszText = szText;
				hdi.cchTextMax = _countof(szText);
				Header_GetItem(hHeader, iItem, &hdi);

				// 计算文本位置（居中）
				UINT uFormat = DT_VCENTER | DT_SINGLELINE;// | DT_CENTER;
				if (hdi.fmt & HDF_LEFT) uFormat = DT_VCENTER | DT_SINGLELINE | DT_LEFT;
				else if (hdi.fmt & HDF_RIGHT) uFormat = DT_VCENTER | DT_SINGLELINE | DT_RIGHT;

				// 绘制文本
				DrawText(pCD->hdc, szText, -1, &rcItem, uFormat);
				// 线位于表头底部
				HPEN hPen = CreatePen(PS_SOLID, 1, RGB(0x80, 0x80, 0x80)); // 灰色线条
				HPEN hOldPen = (HPEN)SelectObject(pCD->hdc, hPen);

				MoveToEx(pCD->hdc, 0, rcItem.bottom - 1, NULL);
				LineTo(pCD->hdc, rcItem.right, rcItem.bottom - 1);

				SelectObject(pCD->hdc, hOldPen);
				DeleteObject(hPen);
				*bHandle = TRUE;
				return CDRF_SKIPDEFAULT; // 跳过默认绘制
			}
			}
		}
	}
	else if (uMsg == WM_NCDESTROY) {
		zyPropertyGrid* zyb = (zyPropertyGrid*)obj->getPtrData(L"this");
		zyb->OnNCDestroy();
	}
	else if (uMsg == WM_HSCROLL || uMsg == WM_VSCROLL || uMsg == WM_MOUSEWHEEL) {
		zyPropertyGrid* p = (zyPropertyGrid*)obj->getPtrData(L"this");
		p->zyPropretyGrid_HideAll();
		//InvalidateRect(hWnd, NULL, TRUE); // 增加强制重绘
	}
	else if (uMsg == WM_SIZE) {
		zyPropertyGrid* p = (zyPropertyGrid*)obj->getPtrData(L"this");
		p->zyPropretyGrid_HideAll();
		int NameWidth = (int)SendMessage(hWnd, LVM_GETCOLUMNWIDTH, 0, 0);
		int valueWidth = LOWORD(lParam) - NameWidth;
		SendMessage(hWnd, LVM_SETCOLUMNWIDTH, 1, valueWidth);
	}
	else if (uMsg == WM_MOUSEMOVE ) {
		RECT rc = { 0 };
		GetClientRect(hWnd, &rc);
		int NameWidth = (int)SendMessage(hWnd, LVM_GETCOLUMNWIDTH, 0, 0);
		rc.left = NameWidth - 5;
		rc.right = NameWidth + 5;
		if (PtInRect(&rc, POINT{ LOWORD(lParam), HIWORD(lParam) }) != 0) {
			HCURSOR hCursor = LoadCursor(0, IDC_SIZEWE);
			SetCursor(hCursor);
		}
		if (obj->hasPtrData(L"DrapX")) {
			RECT rc = { 0 };
			GetClientRect(hWnd, &rc);
			int x =(int)(LONG_PTR)obj->getPtrData(L"DrapX");
			obj->setPtrData(L"DrapX", (void*)LOWORD(lParam));
			x = x - LOWORD(lParam);
			NameWidth = (int)SendMessage(hWnd, LVM_GETCOLUMNWIDTH, 0, 0);
			NameWidth = NameWidth - x;
			int valueWidth = rc.right - rc.left - NameWidth;
			if (NameWidth < 50 || valueWidth < 50) {
				obj->removePtrData(L"DrapX");
				ReleaseCapture();
				return zyCtrol::zyCtrol_WndProc(obj, hWnd, uMsg, wParam, lParam, bHandle);
			}
			if (x > 0) {
				SendMessage(hWnd, LVM_SETCOLUMNWIDTH, 0, NameWidth);
				SendMessage(hWnd, LVM_SETCOLUMNWIDTH, 1, valueWidth);
			}
			else {
				SendMessage(hWnd, LVM_SETCOLUMNWIDTH, 1, valueWidth);
				SendMessage(hWnd, LVM_SETCOLUMNWIDTH, 0, NameWidth);
			}
		}
	}
	else if (uMsg == WM_LBUTTONDOWN) {
		RECT rc = { 0 };
		GetClientRect(hWnd, &rc);
		int NameWidth = (int)SendMessage(hWnd, LVM_GETCOLUMNWIDTH, 0, 0);
		rc.left = NameWidth - 5;
		rc.right = NameWidth + 5;
		zyPropertyGrid* p = (zyPropertyGrid*)obj->getPtrData(L"this");
		if (PtInRect(&rc, POINT{ LOWORD(lParam), HIWORD(lParam) }) != 0) {
			p->zyPropretyGrid_HideAll();
			HCURSOR hCursor = LoadCursor(0, IDC_SIZEWE);
			SetCursor(hCursor);
			obj->setPtrData(L"DrapX", (void*)LOWORD(lParam));
			SetCapture(hWnd);
			*bHandle = TRUE;
			return 0;
		}
		LRESULT ret = p->zyPropretyGrid_OnItemClick(hWnd, LOWORD(lParam), HIWORD(lParam), 0, bHandle);
		if (*bHandle)
			return ret;
	}
	else if (uMsg == WM_LBUTTONUP) {
		RECT rc = { 0 };
		GetClientRect(hWnd, &rc);
		int NameWidth = (int)SendMessage(hWnd, LVM_GETCOLUMNWIDTH, 0, 0);
		rc.left = NameWidth - 5;
		rc.right = NameWidth + 5;
		if (PtInRect(&rc, POINT{ LOWORD(lParam), HIWORD(lParam) }) != 0) {
			HCURSOR hCursor = LoadCursor(0, IDC_SIZEWE);
			SetCursor(hCursor);
		}
		if (obj->hasPtrData(L"DrapX")) {
			obj->removePtrData(L"DrapX");
			ReleaseCapture();
		}
	}
	else if (uMsg == WM_LBUTTONDBLCLK) {
		zyPropertyGrid* p = (zyPropertyGrid*)obj->getPtrData(L"this");
		LRESULT ret = p->zyPropretyGrid_OnItemClick(hWnd, LOWORD(lParam), HIWORD(lParam), 1, bHandle);
		if (*bHandle)
			return ret;
	}
	else if (uMsg == WM_MOUSELEAVE) {
		
		/*int iItem = (int)SendMessage(hWnd, LVM_GETNEXTITEM, 0, LVIS_SELECTED);
		LVITEM item = { 0 };
		SendMessage(hWnd, LVM_SETSELECTIONMARK, 0, 0);
		item.mask = LVIF_STATE;
		item.iItem = iItem;
		item.state = ~LVIS_SELECTED;
		item.stateMask = LVIS_SELECTED;
		SendMessage(hWnd, LVM_SETITEMSTATE, iItem, (LPARAM)&item);*/
			//zyEditBox* pEdit = (zyEditBox*)obj->getPtrData(L"pEdit");
			//ShowWindow(pEdit->getHwnd(), SW_HIDE);

		
			
		//SendMessage(hWnd, LVM_REDRAWITEMS, 0, 0);
	}
	
	else if (uMsg == WM_KILLFOCUS) {
		// 当控件失去焦点时取消所有选中项
		//int iItem = (int)SendMessage(hWnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
		//if (iItem != -1) {
		//	LVITEM item = { 0 };
		//	item.state = 0;
		//	item.stateMask = LVIS_SELECTED;
		//	SendMessage(hWnd, LVM_SETITEMSTATE, iItem, (LPARAM)&item);
		//	// 强制重绘该项以更新显示状态
		//	//SendMessage(hWnd, LVM_REDRAWITEMS, iItem, iItem);
		//	zyPropertyGrid* p = (zyPropertyGrid*)obj->getPtrData(L"this");
		//	p->zyPropretyGrid_HideAll();
		//}
		//*bHandle = TRUE;
		//return 0;
	}
	return zyCtrol::zyCtrol_WndProc(obj, hWnd, uMsg, wParam, lParam, bHandle);
}
void BlackMoonUI::zyPropertyGrid::OnNCDestroy() {
	zyLmageList* pImageList = (zyLmageList*)GetMember(L"pImageList");
	if (pImageList != nullptr) {
		//IUnknown_Release (pImageList);
		pImageList->getObject()->release();
		delete pImageList;
		SetMember(L"pImageList", 0);
	}
	// 递归释放属性项及其子项
	std::vector<PropertyGrid_item*>* Propertys = (std::vector<PropertyGrid_item*>*)GetMember(L"Propertys");
	if (Propertys != nullptr) {
		for (auto* pItem : *Propertys) {
			DeletePropertyItem(pItem);
		}
		delete Propertys;
		SetMember(L"Propertys", 0);
	}
	zyEditBox* pEdit = (zyEditBox*)GetMember(L"pEdit");
	if (pEdit != nullptr) {
		//IUnknown_Release (pEdit);
		pEdit->getObject()->release();
		delete pEdit;
		SetMember(L"pEdit", 0);
	}
	zyListBox* pList = (zyListBox*)GetMember(L"pList");
	if (pList != nullptr) {
		//IUnknown_Release (pEdit);
		pList->getObject()->release();
		delete pList;
		SetMember(L"pList", 0);
	}
	zyWidget* pListWindow = (zyWidget*)GetMember(L"pListWindow");
	if (pListWindow != nullptr) {
		//IUnknown_Release (pEdit);
		pListWindow->getObject()->release();
		delete pListWindow;
		SetMember(L"pListWindow", 0);
	}
	// 释放逻辑类型项的列表数据
	std::vector<std::wstring>* pListStringbool = (std::vector<std::wstring>*)GetMember(L"pListStringbool");
	if (pListStringbool) {
		delete pListStringbool;
		SetMember(L"pListStringbool", 0);
	}

	std::vector<LPARAM>* pListlParambool = (std::vector<LPARAM>*)GetMember(L"pListlParambool");
	if (pListlParambool) {
		delete pListlParambool;
		SetMember(L"pListlParambool", 0);
	}
}
void BlackMoonUI::zyPropertyGrid::DeletePropertyItem(PropertyGrid_item* item) {
	if (!item) return;

	// 递归删除子项
	if (item->Childs) {
		for (auto* child : *item->Childs) {
			DeletePropertyItem(child);
		}
		delete item->Childs;
		item->Childs = nullptr;
	}

	// 根据类型释放资源
	switch (item->Type) {
	case 属性类型_标志位: {
		FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(item->lParam);
		if (listData) {
			for (auto& group : *listData->pListString) {
				delete group.pListlItemData;
			}
			delete listData->pListString;
			delete listData->pListlParam;
			//delete listData;
		}
		break;
	}
	case 属性类型_列表: {
		ListItemData* listData = reinterpret_cast<ListItemData*>(item->lParam);
		if (listData) {
			delete listData->pListString;
			delete listData->pListlParam;
			//delete listData;
		}
		break;
	}
				// 其他需要处理类型的case
	default:
		break;
	}

	// 释放item自身
	delete item;
}
LRESULT BlackMoonUI::zyPropertyGrid::zyPropretyGrid_OnItemClick(HWND hWnd, int x, int y, int mouseState, BOOL* bHandle) {
	LVHITTESTINFO lvht = { {x, y}, 0, 0, 0 };
	SendMessage(hWnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lvht);

	if (lvht.iItem != -1) {
		LVITEM item = { 0 };
		item.mask = LVIF_PARAM;
		item.iItem = lvht.iItem;
		SendMessage(hWnd, LVM_GETITEMW, 0, (LPARAM)&item);

		PropertyGrid_item* pItem = reinterpret_cast<PropertyGrid_item*>(item.lParam);
		if (pItem != nullptr) {
			int type = pItem->Type;
			int level = pItem->Level;
			//std::wstring* subType = (std::wstring*)(pItem->lParam);
			//pugi::xml_node* pNode = (pugi::xml_node*)pItem->lParam;
			// 处理分组类型的点击
			if (type == 属性类型_分组) {
				zyPropretyGrid_ExpandChange(pItem, lvht.iItem);
				return 0;
			}

			// 处理非分组类型的点击
			RECT rc = { 0 };
			SendMessage(hWnd, LVM_GETITEMRECT, lvht.iItem, (LPARAM)&rc);
			rc.left = (level - 1) * 16;
			rc.right = rc.left + 16;
			std::vector<PropertyGrid_item*>* childs= pItem->Childs;
			// 检查是否点击了展开/折叠区域
			if (PtInRect(&rc, lvht.pt) && childs->size()!=0) {
				zyPropretyGrid_ExpandChange(pItem, lvht.iItem);
				return 0;
			}

			// 处理子项的点击
			rc.top = 1;
			SendMessage(hWnd, LVM_GETSUBITEMRECT, lvht.iItem, (LPARAM)&rc);
			if (PtInRect(&rc, lvht.pt) && lvht.iSubItem) {
				rc.left = rc.right - (rc.bottom - rc.top);
				// 处理鼠标按下事件
				if (mouseState == 0) {
					int selected = (int)SendMessage(hWnd, LVM_GETITEMSTATE, lvht.iItem, LVIS_SELECTED);
					if (selected == LVIS_SELECTED) {
						*bHandle = TRUE;
					}
				}

				// 调用点击事件处理函数				
				propertyItem_OnClick(pItem, lvht.iItem, PtInRect(&rc, lvht.pt), mouseState);
				
				return 0;
			}
		}
	}
	return 0;
}
void BlackMoonUI::zyPropertyGrid::zyPropretyGrid_ExpandChange(PropertyGrid_item* pItem, int index) {
	int state = pItem->State;
	if ((state & 属性状态_只读) != 0) {
		return;
	}
	zyPropretyGrid_HideAll();
	std::vector<PropertyGrid_item*>* childs = pItem->Childs;
	HWND hWnd = (HWND)GetMember(L"hWnd");
	if (childs) {
		int count = (int)childs->size();
		if (count == 0) return;
		

		int oldCount = (int)SendMessage(hWnd, LVM_GETITEMCOUNT, 0, 0);
		int pageCount = (int)SendMessage(hWnd, LVM_GETCOUNTPERPAGE, 0, 0);
		if (oldCount - count <= pageCount) {
			SendMessage(hWnd, LVM_SCROLL, 0, 0);
			SendMessage(hWnd, LVM_ENSUREVISIBLE, 0, 0);
		}
		int endindex = index;
		if ((state & 属性状态_扩展) != 0) {
			// 收缩状态：删除所有子项
			state &= ~属性状态_扩展;
			for (int i = count - 1; i >= 0; i--) {  // 逆序删除防止索引变化
				LVITEM item = { 0 };
				item.mask = LVIF_PARAM;
				item.iItem = endindex + 1; // 始终保持删除第一个子项
				if (SendMessage(hWnd, LVM_GETITEM, 0, (LPARAM)&item)) {
					if (item.lParam != 0) {
						PropertyGrid_item* child = (PropertyGrid_item*)item.lParam;
						if (child->Parent == pItem) {
							SendMessage(hWnd, LVM_DELETEITEM, item.iItem, 0);
						}
					}
				}
			}
			// 简化版代码
			//state &= ~属性状态_扩展;
			//for (int i = 0; i < count; i++) {
			//	SendMessage(hWnd, LVM_DELETEITEM, index + 1, 0);
			//}
			// 强制重绘父项及周围区域
			//InvalidateRect(hWnd, NULL, TRUE);
		}
		else {
			// 扩展状态：插入子项
			state |= 属性状态_扩展;
			for (int i = 0; i < count; i++) {
				LVITEM lvitem = { 0 };
				lvitem.mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT;
				lvitem.iItem = endindex + 1 + i; // 插入到父项之后
				lvitem.iSubItem = 0;
				lvitem.state = 0;
				lvitem.stateMask = LVIS_STATEIMAGEMASK;
				PropertyGrid_item* child = (*childs)[i];
				lvitem.pszText = (LPWSTR)child->Name.c_str(); // 使用子项名称
				lvitem.cchTextMax = (int)child->Name.size();
				lvitem.lParam = (LPARAM)child;
				SendMessage(hWnd, LVM_INSERTITEM, 0, (LPARAM)&lvitem);
			}
		}
		pItem->State = state;
		int newCount = (int)SendMessage(hWnd, LVM_GETITEMCOUNT, 0, 0);
		SendMessage(hWnd, LVM_REDRAWITEMS, 0, newCount);//不知道为什么这个刷新导致有绘制残留的背景.所以用下面的强制重绘  添加了LVIF_STATE标识刷新正常
		//InvalidateRect(hWnd, NULL, TRUE);// 强制重绘父项及周围区域
	}
}
void BlackMoonUI::zyPropertyGrid::zyPropretyGrid_HideAll() {
	zyEditBox* pCtrol = (zyEditBox*)GetMember(L"pEdit");
	if (pCtrol != nullptr) {
		HWND hWnd = (HWND)pCtrol->GetMember(L"hWnd");
		if (IsWindowVisible(hWnd) != 0) {
			ShowWindow(hWnd, SW_HIDE);
		}
	}
	zyWidget *pCtrol1 = (zyWidget*)GetMember(L"pListWindow");
	if (pCtrol1 != nullptr) {
		HWND hWnd = (HWND)pCtrol1->GetMember(L"hWnd");
		if (IsWindowVisible(hWnd) != 0) {
			ShowWindow(hWnd, SW_HIDE);
		}
	}
}

LRESULT  BlackMoonUI::zyPropertyGrid::propertyItem_Edit_Msg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL* bHandle) {
    if (msg == WM_KEYUP) {
        if (wParam == VK_RETURN) {
			HANDLE pItem = GetProp(hWnd, L"pItem");
			HANDLE pListView = GetProp(hWnd, L"pListView");
			if (pItem != 0 && pListView != 0) {
				//propertyItem_EndEdit(pListView, pItem, -1); // OnEndEdit;
				ShowWindow(hWnd, SW_HIDE);
			}			
        }
	}
	if (msg == WM_SHOWWINDOW ) {
		if (wParam == 0) { // 被隐藏{
			HANDLE pItem = GetProp(hWnd, L"pItem");
			HANDLE pListView = GetProp(hWnd, L"pListView");
			if(pItem != 0 && pListView != 0){
				propertyItem_EndEdit (pListView, pItem, -1) ; // OnEndEdit;
			} 
		}
	}
	else if (msg == WM_KILLFOCUS) 
		ShowWindow(hWnd, SW_HIDE);
	return 0;
}
LRESULT  BlackMoonUI::zyPropertyGrid::propertyItem_list_Msg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL* bHandle) {
	if (msg == WM_MOUSEMOVE) {
		int iItem = LOWORD(SendMessage(hWnd, LB_ITEMFROMPOINT, 0, lParam));
		if (iItem != -1) { 
			int curentItem = (int)SendMessage(hWnd, LB_GETCURSEL, 0, lParam);
			if (curentItem != iItem) {
				SetFocus(hWnd);
				SendMessage(hWnd, LB_SETCURSEL, iItem, 0);
			}
		}
	}
	else if (msg == WM_KILLFOCUS) {
		ShowWindow(GetParent(hWnd), SW_HIDE);
		HANDLE pListView = GetProp(hWnd, L"pListView");
		if (pListView != 0) {
			HWND hWndLV = (HWND)GetMember(L"hWnd");
			LVHITTESTINFO lvht = { 0 };
			POINT pt = { 0 };
			GetCursorPos(&pt);
			lvht.pt = pt;
			SendMessage(hWndLV, LVM_SUBITEMHITTEST, 0, (LPARAM)& lvht);
			if (lvht.iItem != -1 && lvht.iSubItem == 1) {
				if (SendMessage(hWndLV, LVM_GETITEMSTATE, lvht.iItem, LVIS_SELECTED) == LVIS_SELECTED) 
					SetProp(hWnd, L"NoShow", (HANDLE)1);
				else
					SetProp(hWnd, L"NoShow", (HANDLE)0);
			}
			else
				SetProp(hWnd, L"NoShow", (HANDLE)0);
		}
	}
	return 0;
}
int BlackMoonUI::zyPropertyGrid::propertyItem_List_OnSelected(HWND hWnd, int ID) {
	int index = (int)SendMessage(hWnd, LB_GETCURSEL, 0, 0);
	ShowWindow(GetParent(hWnd), SW_HIDE);
	PropertyGrid_item* pItem = (PropertyGrid_item*)GetProp(hWnd, L"pItem");
	HANDLE pListView = GetProp(hWnd, L"pListView");
	if (pItem != nullptr && pListView != 0) {
		propertyItem_EndEdit(pListView, pItem, index);
	}
	return 0;
}
int BlackMoonUI::zyPropertyGrid::propertyItem_LongText_Dialog_OnCraete(zyForm* form) {
	HWND hWnd = form->getHwnd();
	SendMessage(hWnd, WM_SETICON, 0, 0);
	SendMessage(hWnd, WM_SETICON, 1, 0);
	zyEditBox* LongText_Edit = new zyEditBox();
	LongText_Edit->创建(hWnd, L"", POINT{0,0}, POINT{ 0,0 }, 0, ES_AUTOVSCROLL | ES_WANTRETURN | ES_MULTILINE | WS_TABSTOP | WS_VSCROLL);
	SetMember(L"LongText_Edit", (LONG_PTR)LongText_Edit);

	zyButton* LongText_BtnImport = new zyButton();
	LongText_BtnImport->创建(hWnd, L"导入文本(&I)");
	SetMember(L"LongText_BtnImport", (LONG_PTR)LongText_BtnImport);

	zyButton* LongText_BtnOk = new zyButton();
	LongText_BtnOk->创建(hWnd, L"确认(&O)");
	SetMember(L"LongText_BtnOk", (LONG_PTR)LongText_BtnOk);

	zyButton* LongText_BtnCancel = new zyButton();
	LongText_BtnCancel->创建(hWnd, L"取消(&C)");
	SetMember(L"LongText_BtnCancel", (LONG_PTR)LongText_BtnCancel);

	LongText_BtnOk->事件_被单击(TRegEventCallBack(this, &zyPropertyGrid::LongText_BtnOk_事件_被单击));
	LongText_BtnCancel->事件_被单击(TRegEventCallBack(this, &zyPropertyGrid::LongText_BtnCancel_事件_被单击));
	LongText_BtnImport->事件_被单击(TRegEventCallBack(this, &zyPropertyGrid::LongText_BtnImport_事件_被单击));
	PropertyGrid_item* pItem = (PropertyGrid_item*)form->GetMember(L"pItem");
	if (pItem) {
		LongText_Edit->置文本(pItem->Value);
	}
	return 0;
}
int BlackMoonUI::zyPropertyGrid::propertyItem_LongText_Dialog_OnSize(HWND hWnd, WORD cx, WORD cy) {
	zyEditBox* LongText_Edit = (zyEditBox*)GetMember(L"LongText_Edit");
	zyButton* LongText_BtnImport = (zyButton*)GetMember(L"LongText_BtnImport");
	zyButton* LongText_BtnOk = (zyButton*)GetMember(L"LongText_BtnOk");
	zyButton* LongText_BtnCancel = (zyButton*)GetMember(L"LongText_BtnCancel");
	LongText_Edit->移动(5, 5, cx - 10, cy - 40,0);
	LongText_BtnImport->moveWindow(5, cy - 40 + 10, 100, 24);
	LongText_BtnCancel->moveWindow(cx - 85, cy - 40 + 10, 80, 24);
	LongText_BtnOk->moveWindow(LongText_BtnCancel->左边() - 100 - 5, cy - 40 + 10, 80, 24);

	return 0;
}
int BlackMoonUI::zyPropertyGrid::LongText_BtnOk_事件_被单击(HWND hWnd, int ID) {
	zyDialogBox* LongText_Dialog = (zyDialogBox*)GetMember(L"LongText_Dialog");
	LongText_Dialog->返回值(IDOK);
	std::wstring* pStr = reinterpret_cast<std::wstring*>(LongText_Dialog->GetMember(L"EditText"));
	if (pStr)
		delete pStr;
	zyEditBox* LongText_Edit = (zyEditBox*)GetMember(L"LongText_Edit");
	LongText_Dialog->SetMember(L"EditText", (LONG_PTR)new std::wstring(LongText_Edit->取文本()));
	//delete LongText_Edit;
	//delete LongText_Dialog;
	// 清理控件指针，避免重复删除
	SetMember(L"LongText_Edit", 0);
	SetMember(L"LongText_BtnImport", 0);
	SetMember(L"LongText_BtnOk", 0);
	SetMember(L"LongText_BtnCancel", 0);
	LongText_Dialog->销毁();
	SetMember(L"LongText_Dialog", 0);
	return 0;
}
int BlackMoonUI::zyPropertyGrid::LongText_BtnCancel_事件_被单击(HWND hWnd, int ID) {
	zyDialogBox* LongText_Dialog = (zyDialogBox*)GetMember(L"LongText_Dialog");
	LongText_Dialog->返回值(IDOK);
	LongText_Dialog->销毁();
	return 0;
}
int BlackMoonUI::zyPropertyGrid::LongText_BtnImport_事件_被单击(HWND hWnd, int ID) {
	zyDialogBox* LongText_Dialog = (zyDialogBox*)GetMember(L"LongText_Dialog");
	zyEditBox* LongText_Edit = (zyEditBox*)GetMember(L"LongText_Edit");


	return 0;
}

void BlackMoonUI::zyPropertyGrid::propertyItem_DrawBackAndLine(Gdiplus::Graphics* graphics, int nameWidth, int itemSelect, RECT rc, int isGroup) {
	// 绘制背景
	ARGB backColor = itemSelect != 0 ? (ARGB)GetMember(L"GridSelBackColor") : (ARGB)GetMember(L"GridBackColor");
	graphics->Clear(backColor);

	// 非分组项绘制右侧白色背景
	if (isGroup == 0) {
		Gdiplus::SolidBrush brush(Color::White);
		// 调整填充区域，留出右侧垂直线空间
		graphics->FillRectangle(&brush, nameWidth + 1, 0, rc.right - rc.left - nameWidth - 1, rc.bottom - rc.top);
	}

	// 绘制底部灰色横线
	Gdiplus::Pen pen(Color::Gray);
	graphics->DrawLine(&pen, 0, rc.bottom - rc.top - 1, rc.right - rc.left, rc.bottom - rc.top - 1);

	// 绘制列间垂直线（名称列与值列之间）
	if (isGroup == 0) {
		//int lineX = rc.right - rc.left-1;
		//std::wcout << rc.right - rc.left <<L" 绘制列间垂直线 "<< nameWidth << std::endl;
		graphics->DrawLine(&pen, nameWidth, 0, nameWidth, rc.bottom - rc.top);
		//graphics->DrawLine(&pen, lineX, 0, lineX, rc.bottom - rc.top);
	}

}
void BlackMoonUI::zyPropertyGrid::propertyItem_DrawExpanding(bool Open, HWND hWnd, HDC hdc, int left, int top, int right, int bottom) {
	// 尝试使用主题绘制扩展/收缩图标
	HTHEME hTheme = OpenThemeData(hWnd, L"TREEVIEW");
	if (hTheme != NULL) {
		RECT rc = { left + 2, top, left + 18, bottom };
		DrawThemeBackground(hTheme, hdc, TVP_GLYPH, Open ? GLPS_OPENED : GLPS_CLOSED, &rc, NULL);
		CloseThemeData(hTheme);
	}
	else {
		// 使用 GDI+ 绘制扩展/收缩图标
		Gdiplus::Graphics graphics(hdc);
		Gdiplus::Pen pen(Gdiplus::Color::Gray);

		int y = top + (bottom - top - 8) / 2;
		RECT rc = { left + 2, y, left + 2 + 8, y + 8 };

		// 绘制矩形
		graphics.DrawRectangle(&pen, rc.left, rc.top, 8, 8);

		// 绘制水平线
		graphics.DrawLine(&pen, (REAL)(rc.left + 2), (REAL)(rc.top + 4), (REAL)(rc.right - 2), (REAL)(rc.top + 4));

		// 如果未展开，绘制垂直线
		if (!Open) {
			graphics.DrawLine(&pen, (REAL)(rc.left + 4), (REAL)(rc.top + 2), (REAL)(rc.left + 4), (REAL)(rc.bottom - 2));
		}
	}
}
void BlackMoonUI::zyPropertyGrid::propertyItem_DrawNameAndStringValue(HWND hWnd, HDC hdc, PropertyGrid_item* pItem, Gdiplus::Graphics* graphics,
	int itemSelect, RECT rc, int nameWidth, int stringOffset, int stringFontStyle)
{
	// 线程安全的局部StringFormat（每次调用独立创建）
	Gdiplus::StringFormat format;
	format.SetLineAlignment(Gdiplus::StringAlignmentCenter);
	format.SetFormatFlags(Gdiplus::StringFormatFlagsNoWrap | Gdiplus::StringFormatFlagsMeasureTrailingSpaces);

	// 线程安全的临时画刷
	const ARGB textColor = itemSelect ?(ARGB)GetMember(L"GridSelTextColor") :(ARGB)pItem->TextColor;
	Gdiplus::SolidBrush textBrush(textColor);
	

	// 获取属性类型和层级
	const int type = pItem->Type;
	const int level = (type == 属性类型_分组) ? 0 : (pItem->Level - 1);

	// 创建字体对象（确保线程本地资源）
	HFONT hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
	Gdiplus::Font font(hdc, hFont);  // 直接使用栈对象避免动态分配

	// 绘制属性名称
	const Gdiplus::RectF nameRect((REAL)(level * 16 + 18),0.0f,(REAL)(rc.right - rc.left - 18),(REAL)(rc.bottom - rc.top));
	graphics->DrawString(pItem->Name.c_str(),-1,&font,nameRect,&format,&textBrush);

	// 绘制值区域背景
	if (type != 属性类型_分组) {
		Gdiplus::SolidBrush backBrush(Color::White);
		graphics->FillRectangle(&backBrush,(REAL)(nameWidth + 1),0.0f,(REAL)(rc.right - rc.left - nameWidth-3),(REAL)(rc.bottom - rc.top - 1));
	}
	
	if (type == 属性类型_颜色) {
		//pItem->Value = std::to_wstring(pItem->currentIndex);
		Gdiplus::SolidBrush backBrush(zyRGB2ARGB(pItem->currentIndex,255));
		graphics->FillRectangle(&backBrush, (int)(nameWidth + 3), 1, rc.bottom - rc.top - 2, rc.bottom - rc.top - 3);
	}
	/*std::vector<std::wstring>* pListString = (std::vector<std::wstring>*)GetMember(L"pListString");
	if (pListString && pListString->size() > 0) {
		int val = -1;
		std::wistringstream iss(pItem->Value);
		iss >> val;
		if (val!= -1 && val  < pListString->size())
			pItem->Value = (*pListString)[val];
	}*/
	// 绘制字符串值
	if (!pItem->Value.empty() ) {
		// 增强：值区域有效性检查
		if (nameWidth <= 0 || rc.right - rc.left <= nameWidth) return;

		// 正确计算值区域坐标
		Gdiplus::RectF valueRect((REAL)(nameWidth + stringOffset + 5),0.0f,
			(REAL)(rc.right - rc.left - nameWidth - stringOffset - 5), // 防止越界
			(REAL)(rc.bottom - rc.top));
		if (stringFontStyle != 0) {
			Gdiplus::FontFamily fontFamily;
			font.GetFamily(&fontFamily);
			Gdiplus::Font styleFont(&fontFamily,font.GetSize(),stringFontStyle,font.GetUnit());
			graphics->DrawString(pItem->Value.c_str(),-1,&styleFont,valueRect,&format,&textBrush);
		}
		else {
			//Gdiplus::SolidBrush backBrush(Color::Coral);
			//graphics->FillRectangle(&backBrush, valueRect);
			if (type == 属性类型_颜色) {
				valueRect.X += 18;
				graphics->DrawString(pItem->Value.c_str(), -1, &font, valueRect, &format, &textBrush);
			}
			else
				graphics->DrawString(pItem->Value.c_str(), -1, &font, valueRect, &format, &textBrush);
		}
	}
}
LRESULT BlackMoonUI::zyPropertyGrid::propertyItem_OnDraw(PropertyGrid_item* pItem, LPARAM lParam){
	// 实现代码
	if (pItem){
		NMLVCUSTOMDRAW* nmlv = reinterpret_cast<NMLVCUSTOMDRAW*>(lParam);
		const HWND hListView = nmlv->nmcd.hdr.hwndFrom; // 缓存列表控件句柄
		if (nmlv->nmcd.dwItemSpec >= (DWORD)SendMessage(hListView, LVM_GETITEMCOUNT, 0, 0))
			return CDRF_SKIPDEFAULT; // 防止绘制不存在的项
		// 合并获取矩形和列宽操作
		RECT rc = { 0 };
		const int nameWidth = (int)SendMessage(hListView, LVM_GETCOLUMNWIDTH, 0, 0);

		if (nameWidth <= 0 || !SendMessage(hListView, LVM_GETITEMRECT, nmlv->nmcd.dwItemSpec, (LPARAM)&rc)){
			return CDRF_SKIPDEFAULT; // 无效数据直接返回
		}
		//std::wcout << "nameWidth: " << nmlv->nmcd.dwItemSpec << std::endl;
		// 获取选择状态
		int isSelect = (int)SendMessage(hListView, LVM_GETITEMSTATE, nmlv->nmcd.dwItemSpec, LVIS_SELECTED);
		zyBuffGraphics buff;// = new zyBuffGraphics();
		
		int width = rc.right - rc.left;
		int height = rc.bottom - rc.top;
		if(!buff.Create(width, height)) return 0;

		Gdiplus::Graphics* g = buff.GetGraphics();
		const HDC hdcBuffer = buff.gethdc();
		// 绘制背景和线条 (优化内部资源重用)
		const bool hasChildren = pItem->Childs && !pItem->Childs->empty();
		propertyItem_DrawBackAndLine(g, nameWidth, isSelect, rc, hasChildren ? 1 : 0);
		// 绘制扩展按钮 (条件判断前置)
		if (hasChildren){
			const bool isExpanded = (pItem->State & 属性状态_扩展) != 0;
			const int indentLevel = pItem->Level * 16; // 缩进量计算
			propertyItem_DrawExpanding(isExpanded, hListView, hdcBuffer, indentLevel, 0, rc.right, height);
		}
		if (pItem->Type == 属性类型_列表) {
			ListItemData* listData = reinterpret_cast<ListItemData*>(pItem->lParam);
			std::vector<std::wstring>* pListString = listData->pListString;
			if (pListString && !pListString->empty()) {
				// 从当前项的currentIndex获取值
				if (pItem->currentIndex >= 0 && pItem->currentIndex < pListString->size()) {
					pItem->Value = (*pListString)[pItem->currentIndex];
				}
			}
		}
		else if (pItem->Type == 属性类型_逻辑) {
			std::vector<std::wstring>* pListString = (std::vector<std::wstring>*)GetMember(L"pListStringbool");
			if (pListString && !pListString->empty()) {
				// 从当前项的currentIndex获取值
				if (pItem->currentIndex >= 0 && pItem->currentIndex < pListString->size()) {
					pItem->Value = (*pListString)[pItem->currentIndex];
				}
			}
		}
		else if (pItem->Type == 属性类型_颜色) {
			// 确保颜色值在0x000000到0xFFFFFF范围内

            
			//pItem->currentIndex = _wtoi(pItem->Value.c_str());
			
			const UINT32 colorValue = pItem->currentIndex & 0xFFFFFF;
			const int b = (colorValue >> 16) & 0xFF; // 注意：原代码可能存在颜色分量顺序错误
			const int g1 = (colorValue >> 8) & 0xFF;
			const int r = colorValue & 0xFF;
			
			pItem->Value = L"(" + std::to_wstring(r) + L"," + std::to_wstring(g1) + L"," + std::to_wstring(b) + L")";
			
			Gdiplus::SolidBrush backBrush(Color::Gray);
			g->FillEllipse(&backBrush, (int)(nameWidth + 3),  1, rc.bottom - rc.top - 2, rc.bottom - rc.top - 3);
		}

		propertyItem_DrawNameAndStringValue(hListView, hdcBuffer, pItem, g, isSelect, rc, nameWidth, 0, 0);
		//长文本按钮
		if (isSelect != 0 && (pItem->State & 属性状态_只读) == 0 && pItem->Type == 属性类型_长文本) {
			propertyItem_DrawButton(hListView, hdcBuffer, g, 属性类型_长文本, rc);
		}
		else if (isSelect != 0 && (pItem->State & 属性状态_只读) == 0 && pItem->Type == 属性类型_列表) {
			propertyItem_DrawButton(hListView, hdcBuffer, g, 属性类型_列表, rc);
		}
		else if (isSelect != 0 && (pItem->State & 属性状态_只读) == 0 && pItem->Type == 属性类型_逻辑) {
			propertyItem_DrawButton(hListView, hdcBuffer, g, 属性类型_逻辑, rc);
		}
		else if (isSelect != 0 && (pItem->State & 属性状态_只读) == 0 && pItem->Type == 属性类型_颜色) {
			propertyItem_DrawButton(hListView, hdcBuffer, g, 属性类型_颜色, rc);
		}
		else if (isSelect != 0 && (pItem->State & 属性状态_只读) == 0 && pItem->Type == 属性类型_标志位) {
			propertyItem_DrawButton(hListView, hdcBuffer, g, 属性类型_标志位, rc);
		}
		else if (isSelect != 0 && (pItem->State & 属性状态_只读) == 0 && pItem->Type == 属性类型_字体) {
			propertyItem_DrawButton(hListView, hdcBuffer, g, 属性类型_字体, rc);
		}
		else if (isSelect != 0 && (pItem->State & 属性状态_只读) == 0 && pItem->Type == 属性类型_图片) {
			propertyItem_DrawButton(hListView, hdcBuffer, g, 属性类型_图片, rc);
		}
		buff.Copy2dc(nmlv->nmcd.hdc, rc.left, rc.top, width, height);

	}
	return 1;
}
void BlackMoonUI::zyPropertyGrid::propertyItem_DrawButton(HWND hWnd, HDC hdc, Gdiplus::Graphics* graphics,int type, RECT rc) {
	RECT rc2 = rc;
	int height = rc2.bottom - rc2.top;
	rc2.left = rc2.right - height - 1;
	rc2.top = 0;
	rc2.bottom = height - 1;

	Gdiplus::SolidBrush backBrush(Color::White);
	graphics->FillRectangle(&backBrush, (int)(rc2.left - 2), rc2.top, (int)(rc2.right - rc2.left + 2), (int)(rc2.bottom - rc2.top));
	backBrush.SetColor(Color::Black);
	if (type == 属性类型_长文本 || type == 属性类型_颜色 || type == 属性类型_字体 || type == 属性类型_标志位) {
		HTHEME hTheme = OpenThemeData(hWnd,L"Button");
		if (hTheme == 0) {
			DrawFrameControl(hdc, &rc2, DFC_BUTTON, DFCS_BUTTONPUSH | 0);
		}
		else {
			DrawThemeBackground(hTheme, hdc, BP_PUSHBUTTON, PBS_NORMAL, &rc2, 0);
			CloseThemeData(hTheme);
		}
		graphics->FillEllipse(&backBrush, (int)(rc2.left +(height - 12) / 2 + 1), (int)(height / 2 - 1), 3, 3);
		graphics->FillEllipse(&backBrush, (int)(rc2.left +(height - 12) / 2 + 5), (int)(height / 2 - 1), 3, 3);
		graphics->FillEllipse(&backBrush, (int)(rc2.left + (height - 12) / 2 + 9), (int)(height / 2 - 1), 3, 3);

	}else if (type == 属性类型_列表 || type == 属性类型_逻辑 ) {
		HTHEME hTheme = OpenThemeData(hWnd, L"COMBOBOX");
		if (hTheme == 0) {
			DrawFrameControl(hdc, &rc2, DFC_BUTTON, DFCS_BUTTONPUSH | 0);
			PointF points[3] = {
				{ (REAL)(rc2.left + (height - 12) / 2 ), (REAL)(height / 2 - 2) },
				{ (REAL)(rc2.left + (height - 12) / 2 + 10), (REAL)(height / 2 - 2) },
				{ (REAL)(rc2.left + (height - 12) / 2 + 5), (REAL)(height / 2 - 2 + 5) }
			};
			graphics->FillPolygon(&backBrush, points,3);
		}
		else {
			DrawThemeBackground(hTheme, hdc, CP_DROPDOWNBUTTON, CBXS_NORMAL, &rc2, 0);
			CloseThemeData(hTheme);
		}
	}

}
void BlackMoonUI::zyPropertyGrid::propertyItem_ShowList(PropertyGrid_item* pItem, int index) {
	HWND hwnd = (HWND)GetMember(L"hWnd");
	zyWidget* pListWindow = (zyWidget*)GetMember(L"pListWindow");
	zyListBox* pList = (zyListBox*)GetMember(L"pList");
	if (pListWindow != nullptr && pList != nullptr) {
		if (pList->取属性(L"NoShow") != 0) {
			pList->置属性(L"NoShow", 0);
			return;
		}
		if (pListWindow->是否可视() == false && pList->取属性(L"NoShow") == 0) {
			pList->置属性(L"pItem", pItem);
			pList->清空();
			int val = 0;
			std::wistringstream iss(pItem->Value);
			iss >> val;
			std::vector<std::wstring>* pListString = nullptr;
			std::vector<LPARAM>* pListlParam = nullptr;
			if (pItem->Type == 属性类型_逻辑) {
				pListString = (std::vector<std::wstring>*)GetMember(L"pListStringbool");
				pListlParam = (std::vector<LPARAM>*)GetMember(L"pListlParambool");
			}
			else {
				ListItemData* listData = reinterpret_cast<ListItemData*>(pItem->lParam);
				if (!listData) return;
				pListString = listData->pListString;
				pListlParam = listData->pListlParam;
			}
			
			if (!pListString->empty() && !pListlParam->empty()) {
				int count = (int)pListString->size();
				for (int i = 0; i < count; i++) {
					pList->加入项目(pListString->at(i), (int)pListlParam->at(i));
				}
				RECT itemRect = pList->取项目矩形(count - 1);
				int itemHeight = (itemRect.bottom - itemRect.top) * count + 5;
				if (itemHeight > 200) itemHeight = 200;
				RECT rc1 = { 0 };
				SystemParametersInfo(SPI_GETWORKAREA, 0, &rc1, 0);
				int screenHeight = rc1.bottom;
				RECT rc = { 0 };
				rc.top = 1;
				SendMessage(hwnd, LVM_GETSUBITEMRECT, index, (LPARAM) &rc);
				POINT pt = { rc.left , rc.top };
				ClientToScreen(hwnd, &pt);
				if (rc.bottom + itemHeight > screenHeight)
					pListWindow->moveWindow(rc.left, rc.top - itemHeight, rc.right - rc.left, itemHeight);
				else {
					pListWindow->moveWindow(pt.x, pt.y + 20 , rc.right - rc.left, itemHeight);
				}
				pList->moveWindow(0, 0, pListWindow->宽度(), pListWindow->高度());
				zyForm* topWindow = new zyForm;
				topWindow->_BindWindow(GetAncestor(hwnd, GA_ROOT));
				SetMember(L"oldKeepTitle", topWindow->保持标题栏激活());
				topWindow->保持标题栏激活(true);
				pListWindow->可视(true);
				pList->获取焦点();
				pList->置现行选中项(val);
			}
		}
		else
			zyPropretyGrid_HideAll();
	}
}
int BlackMoonUI::zyPropertyGrid::propertyItem_ShowEdit(PropertyGrid_item* pItem, int iItem, int offsetLeft, int offsetRight) {
	zyEditBox* pEdit = (zyEditBox*)GetMember(L"pEdit");
	if(!pEdit) return 0;
	HWND hWndListView = (HWND)GetMember(L"hWnd");
	HWND hWndEdit = (HWND)pEdit->GetMember(L"hWnd");
	if (IsWindow(hWndListView) != 0 && IsWindowVisible(hWndEdit) == 0) {
		pEdit->置属性(L"pItem", pItem);
		pEdit->背景色(RGB(255, 255, 255));
		RECT rc= { 0 };
		rc.top = 1;
		SendMessage(hWndListView, LVM_GETSUBITEMRECT, iItem, (LPARAM) & rc);
		pEdit->移动(rc.left + 4 + offsetLeft, rc.top + 2, rc.right - rc.left - 8 - offsetRight - offsetLeft, rc.bottom - rc.top - 3, true);
		if (!pItem->Value.empty())
			pEdit->置文本(pItem->Value);
		else
			pEdit->置文本(L"");
		pEdit->置内容改变标志(false);
		pEdit->可视(true);

		return 1;
	}
	return 0;
}
int BlackMoonUI::zyPropertyGrid::propertyItem_BeginEdit(PropertyGrid_item* pItem, int index) {
	// 实现代码
	zyPropretyGrid_HideAll();
	// 添加类型和状态检查
	if (pItem->Type == 属性类型_分组 || (pItem->State & 属性状态_只读) != 0 )
		return 1;
	TRegEvent* p = GetRegEvent(L"OnBeginEdit");
	HWND hWnd = (HWND)GetMember(L"hWnd");
	if (p) {
		int ret = p->handler<int>(hWnd, pItem);
		if (ret != 0)
			return 1;
	}
	if (pItem->Type == 属性类型_文本) {
		if ((pItem->State & 属性状态_只读仅编辑框) != 0)
			return 1;
		return propertyItem_ShowEdit(pItem, index, 0, 0);
	}
	else if (pItem->Type == 属性类型_长文本) {
		if((pItem->State & 属性状态_只读仅编辑框) != 0)
			return 1;
		RECT rc = { 0 };
		rc.top = 1;
		SendMessage(hWnd, LVM_GETSUBITEMRECT, index, (LPARAM)&rc);
		return propertyItem_ShowEdit(pItem, index, 0, rc.bottom - rc.top + 2);
	}
	else if (pItem->Type == 属性类型_标志位) {
		RECT rc = { 0 };
		rc.top = 1;
		SendMessage(hWnd, LVM_GETSUBITEMRECT, index, (LPARAM)&rc);
		return propertyItem_ShowEdit(pItem, index, 0, rc.bottom - rc.top + 2);
	}
	else if (pItem->Type == 属性类型_列表 || pItem->Type == 属性类型_逻辑) {
		TRegEvent* p = GetRegEvent(L"OnBeginEdit");
		if (p) {
			int ret = p->handler<int>(GetMember(L"hWnd"), pItem);
			if (ret != 0)
				return 1;
		}
	}
	else if (pItem->Type == 属性类型_颜色) {
		if ((pItem->State & 属性状态_只读) != 0)
			return 1;
		RECT rc = { 0 };
		rc.top = 1;
		SendMessage(hWnd, LVM_GETSUBITEMRECT, index, (LPARAM)&rc);
		propertyItem_ShowEdit( pItem, index, rc.bottom - rc.top - 2, rc.bottom - rc.top + 2);

	}
	
	return 0;
}
int BlackMoonUI::zyPropertyGrid::propertyItem_EndEdit(HANDLE grid, HANDLE pItem, int index) {
	// 实现代码
	PropertyGrid_item* pItem1 = (PropertyGrid_item*)pItem;
	if (pItem1->Type == 属性类型_分组 || (pItem1->State & 属性状态_只读) != 0)
		return 1;
	
	if (pItem1->Type == 属性类型_文本 || pItem1->Type == 属性类型_长文本 || pItem1->Type == 属性类型_颜色 || pItem1->Type == 属性类型_标志位) {
		zyEditBox* pEdit = (zyEditBox*)GetMember(L"pEdit");
		if (!pEdit) return 0;
		if (pEdit->内容是否改变()) {	
			std::wstring pStr = pEdit->取文本();
			if (pItem1->Value != pStr)
				pItem1->Value = pStr;
			TRegEvent* p = (TRegEvent*)GetRegEvent(L"OnValueChange");
			if (p) {
				int ret = p->handler<int>(GetMember(L"hWnd"), pItem1,0);
				if(ret)
					return 1;
			}
			/*pStr = pEdit->取文本();
			if (pItem1)
				pItem1->Value = pStr;*/
			return 1;
		}
	}
	else if (pItem1->Type == 属性类型_列表 || pItem1->Type == 属性类型_逻辑) {
		pItem1->currentIndex = index;
		HWND hwnd = (HWND)GetMember(L"hWnd");
		int listIndex = (int)SendMessage(hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
		SendMessage(hwnd, LVM_REDRAWITEMS, listIndex, listIndex);
		TRegEvent* p = (TRegEvent*)GetRegEvent(L"OnValueChange");
		if (p) {
			p->handler<int>(hwnd, pItem,0);
		}
	}
	return 0;
}
int BlackMoonUI::zyPropertyGrid::propertyItem_OnClick(PropertyGrid_item* pItem,int index,int isOnButton,int mouseState) {
	if (pItem->Type == 属性类型_分组 || (pItem->State & 属性状态_只读) != 0) {
		// 实现代码
		TRegEvent* p = GetRegEvent(L"OnClick");
		if (p) {
			int ret = p->handler<int>(GetMember(L"hWnd"), pItem, isOnButton);
			if (ret != 0)
				return 1;
		}
		zyPropretyGrid_ExpandChange(pItem, index);

		return 1;
	}
	else if (pItem->Type == 属性类型_文本){
		if((pItem->State & 属性状态_只读) != 0) return 1;
		return propertyItem_BeginEdit(pItem, index);
	}
	else if (pItem->Type == 属性类型_长文本) {
		if ((pItem->State & 属性状态_只读) != 0) return 1;
		HWND hwnd = (HWND)GetMember(L"hWnd");
		if (isOnButton == 0)
			return propertyItem_BeginEdit(pItem, index);
		else {
			int state = (int)SendMessage(hwnd, LVM_GETITEMSTATE, index, LVIS_SELECTED);
			if (state == LVIS_SELECTED) {
				zyPropretyGrid_HideAll();
				TRegEvent* p = GetRegEvent(L"OnClick");
				if (p) {
					int ret = p->handler<int>(hwnd, pItem, isOnButton);
					if (ret != 0)
						return 1;
				}
				zyDialogBox* LongText_Dialog = new zyDialogBox();
				LongText_Dialog->边框(窗口边框_普通可调边框);
				LongText_Dialog->SetMember(L"pItem", (LONG_PTR)pItem);
				LongText_Dialog->事件_创建完毕(TRegEventCallBack(this,&zyPropertyGrid::propertyItem_LongText_Dialog_OnCraete));
				LongText_Dialog->事件_尺寸被改变(TRegEventCallBack(this, &zyPropertyGrid::propertyItem_LongText_Dialog_OnSize));
				LongText_Dialog->置开始位置(开始位置_居中屏幕);
				LongText_Dialog->Esc关闭(true);
				SetMember(L"LongText_Dialog",(LONG_PTR)LongText_Dialog);
				int ret = (int)LongText_Dialog->载入(GetAncestor(hwnd, GA_ROOT), L"请输入文本：", POINT{ 0, 0 }, POINT{ 250, 180 },
					WS_VISIBLE | WS_MAXIMIZEBOX | WS_DLGFRAME, WS_EX_DLGMODALFRAME, true);
				if (ret == IDOK) {
					LONG_PTR pEditText = LongText_Dialog->GetMember(L"EditText");
					if (pEditText) {
						std::wstring* pEditText_str = reinterpret_cast<std::wstring*>(pEditText);
						pItem->Value = *pEditText_str;
						delete pEditText_str; // 释放内存
						LongText_Dialog->SetMember(L"EditText",0);
					}
					SendMessage(hwnd, LVM_REDRAWITEMS, index, index);
					TRegEvent* p = GetRegEvent(L"OnValueChange");
					if (p) {
						p->handler<int>(hwnd, pItem,0);
					}
					//return 1;
				}
				//销毁对话框后释放内存

				/*std::vector<std::wstring>* pListString = (std::vector<std::wstring>*)GetMember(L"pListString");
				std::vector<LPARAM>* pListlParam = (std::vector<LPARAM>*)GetMember(L"pListlParam");
				if (pListString) {
					for (int i = 0; i < pListString->size(); i++) {
						pListString->clear();
					}
					delete pListString;
				}
				if (pListlParam) {
					for (int i = 0; i < pListlParam->size(); i++) {
						pListlParam->clear();
					}
					delete pListlParam;
				}*/
				zyEditBox* LongText_Edit = (zyEditBox*)GetMember(L"LongText_Edit");
				if(LongText_Edit)
					delete LongText_Edit;
				zyButton* LongText_BtnImport = (zyButton*)GetMember(L"LongText_BtnImport");
				if (LongText_BtnImport)
					delete LongText_BtnImport;
				zyButton* LongText_BtnCancel = (zyButton*)GetMember(L"LongText_BtnCancel");
				if (LongText_BtnCancel)
					delete LongText_BtnCancel;
				zyButton* LongText_BtnOk = (zyButton*)GetMember(L"LongText_BtnOk");
				if (LongText_BtnOk)
					delete LongText_BtnOk;
				delete LongText_Dialog;
				return 1;
			}
		}
	}
	else if (pItem->Type == 属性类型_列表) {
		if ((pItem->State & 属性状态_只读) != 0) return 1;
		HWND hwnd = (HWND)GetMember(L"hWnd");
		int selected = (int)SendMessage(hwnd, LVM_GETITEMSTATE, index, LVIS_SELECTED);
		if (mouseState == 0 || mouseState == 1) {
			if (selected != LVIS_SELECTED) {
				zyPropretyGrid_HideAll();
			}
			else {
				TRegEvent* p = GetRegEvent(L"OnClick");
				if (p) {
					int ret = p->handler<int>(hwnd, pItem, isOnButton);
					if (ret != 0)
						return 1;
				}
				propertyItem_ShowList(pItem, index);
			}
		}
	}
	else if (pItem->Type == 属性类型_逻辑) {
		if ((pItem->State & 属性状态_只读) != 0) return 1;
		HWND hwnd = (HWND)GetMember(L"hWnd");
		int selected = (int)SendMessage(hwnd, LVM_GETITEMSTATE, index, LVIS_SELECTED);
		if (mouseState == 0 || mouseState == 1) {
			if (selected != LVIS_SELECTED) {
				zyPropretyGrid_HideAll();
			}
			else {
				TRegEvent* p = GetRegEvent(L"OnClick");
				if (p) {
					int ret = p->handler<int>(hwnd, pItem, isOnButton);
					if (ret != 0)
						return 1;
				}
			}
			if (isOnButton!=0) {
				propertyItem_ShowList(pItem, index);
			}
			
			if (mouseState == 1) {
				zyPropretyGrid_HideAll();
				int i = pItem->currentIndex;
				if (i == -1)
					i = 0;
				else if (i == 0)
					i = 1;
				else if (i == 1)
					i = 0;
				pItem->currentIndex = i;
				SendMessage(hwnd, LVM_REDRAWITEMS, index, index);
				TRegEvent* p = GetRegEvent(L"OnValueChange");
				if (p) {
					p->handler<int>(hwnd, pItem, 0);
				}
			}
		}		

	}
	else if (pItem->Type == 属性类型_颜色) {
		if ((pItem->State & 属性状态_只读) != 0) return 1;
		HWND hwnd = (HWND)GetMember(L"hWnd");
		int selected = (int)SendMessage(hwnd, LVM_GETITEMSTATE, index, LVIS_SELECTED);
		if (mouseState == 0 || mouseState == 1) {
			if (selected != LVIS_SELECTED) {
				zyPropretyGrid_HideAll();
			}
		}
		if (isOnButton != 0) {
			zyPropretyGrid_HideAll();
			TRegEvent* p = GetRegEvent(L"OnClick");
			if (p) {
				int ret = p->handler<int>(hwnd, pItem, isOnButton);
				if (ret != 0)
					return 1;
			}	
			zyColorDialog* Color_Dialog = new zyColorDialog();
			Color_Dialog->初始化(CC_FULLOPEN, pItem->currentIndex);
			Color_Dialog->置开始位置(开始位置_居中父窗口);
			if (Color_Dialog->打开(hwnd)) {
				pItem->currentIndex = Color_Dialog->取颜色值();
				SendMessage(hwnd, LVM_REDRAWITEMS, index, index);
				TRegEvent* p = GetRegEvent(L"OnValueChange");
				if (p) {
					p->handler<int>(hwnd, pItem, 0);
				}
				delete Color_Dialog;
			}
		}
		else
			propertyItem_BeginEdit(pItem, index);
	}
	else if (pItem->Type == 属性类型_标志位) {
		return propertyItem_Flags_OnClick(pItem, index, isOnButton, mouseState);
	}
	else if (pItem->Type == 属性类型_字体) {
		if ((pItem->State & 属性状态_只读) != 0) return 1;
		HWND hwnd = (HWND)GetMember(L"hWnd");
		int selected = (int)SendMessage(hwnd, LVM_GETITEMSTATE, index, LVIS_SELECTED);
		if (mouseState == 0 || mouseState == 1) {
			zyPropretyGrid_HideAll();
			if (selected == LVIS_SELECTED) {
				TRegEvent* p = GetRegEvent(L"OnClick");
				if (p) {
					int ret = p->handler<int>(hwnd, pItem, isOnButton);
					if (ret != 0)
						return 1;
				}
				HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
				LOGFONT lf = {0};
				GetObject(hFont, sizeof(LOGFONT), &lf);
				wcscpy_s(lf.lfFaceName, L"宋体"); // 默认字体名称
				//lf.lfHeight = 20; // 默认字体大小
				zyFontDialog* Font_Dialog = new zyFontDialog();
				Font_Dialog->初始化(0, &lf);
				Font_Dialog->置开始位置(开始位置_居中父窗口);
				if (Font_Dialog->打开(hwnd)) {
					LPLOGFONTW font = Font_Dialog->取字体();
					pItem->Value  = std::wstring(font->lfFaceName)+ std::wstring(L",") + std::to_wstring(-font->lfHeight);
					SendMessage(hwnd, LVM_REDRAWITEMS, index, index);
					TRegEvent* p = GetRegEvent(L"OnValueChange");
					if (p) {
						p->handler<int>(hwnd, pItem, 0);
					}
					delete Font_Dialog;
				}
			}
		}
	}
	else if (pItem->Type == 属性类型_图片) {
		if ((pItem->State & 属性状态_只读) != 0) return 1;
		HWND hwnd = (HWND)GetMember(L"hWnd");
		if (isOnButton == 0)
			propertyItem_BeginEdit(pItem, index);
		else {
			int state = (int)SendMessage(hwnd, LVM_GETITEMSTATE, index, LVIS_SELECTED);
			if (state == LVIS_SELECTED) {
				zyPropretyGrid_HideAll();
				TRegEvent* p = GetRegEvent(L"OnClick");
				if (p) {
					int ret = p->handler<int>(hwnd, pItem, isOnButton);
					if (ret != 0)
						return 1;
				}
				zyDialogBox* LongText_Dialog = new zyDialogBox();
				LongText_Dialog->边框(窗口边框_普通可调边框);
				LongText_Dialog->SetMember(L"pItem", (LONG_PTR)pItem);
				LongText_Dialog->事件_创建完毕(TRegEventCallBack(this, &zyPropertyGrid::propertyItem_LongText_Dialog_OnCraete));
				LongText_Dialog->事件_尺寸被改变(TRegEventCallBack(this, &zyPropertyGrid::propertyItem_LongText_Dialog_OnSize));
				LongText_Dialog->置开始位置(开始位置_居中屏幕);
				LongText_Dialog->Esc关闭(true);
				SetMember(L"LongText_Dialog", (LONG_PTR)LongText_Dialog);
				int ret = (int)LongText_Dialog->载入(GetAncestor(hwnd, GA_ROOT), L"请输入文本：", POINT{ 0, 0 }, POINT{ 250, 180 },
					WS_VISIBLE | WS_MAXIMIZEBOX | WS_DLGFRAME, WS_EX_DLGMODALFRAME, true);
				if (ret == IDOK) {
					LONG_PTR pEditText = LongText_Dialog->GetMember(L"EditText");
					if (pEditText) {
						std::wstring* pEditText_str = reinterpret_cast<std::wstring*>(pEditText);
						pItem->Value = *pEditText_str;
						delete pEditText_str; // 释放内存
						LongText_Dialog->SetMember(L"EditText", 0);
					}
					SendMessage(hwnd, LVM_REDRAWITEMS, index, index);
					TRegEvent* p = GetRegEvent(L"OnValueChange");
					if (p) {
						p->handler<int>(hwnd, pItem, 0);
					}
					//return 1;
				}
				//销毁对话框后释放内存

				/*std::vector<std::wstring>* pListString = (std::vector<std::wstring>*)GetMember(L"pListString");
				std::vector<LPARAM>* pListlParam = (std::vector<LPARAM>*)GetMember(L"pListlParam");
				if (pListString) {
					for (int i = 0; i < pListString->size(); i++) {
						pListString->clear();
					}
					delete pListString;
				}
				if (pListlParam) {
					for (int i = 0; i < pListlParam->size(); i++) {
						pListlParam->clear();
					}
					delete pListlParam;
				}*/
				zyEditBox* LongText_Edit = (zyEditBox*)GetMember(L"LongText_Edit");
				if (LongText_Edit)
					delete LongText_Edit;
				zyButton* LongText_BtnImport = (zyButton*)GetMember(L"LongText_BtnImport");
				if (LongText_BtnImport)
					delete LongText_BtnImport;
				zyButton* LongText_BtnCancel = (zyButton*)GetMember(L"LongText_BtnCancel");
				if (LongText_BtnCancel)
					delete LongText_BtnCancel;
				zyButton* LongText_BtnOk = (zyButton*)GetMember(L"LongText_BtnOk");
				if (LongText_BtnOk)
					delete LongText_BtnOk;
				delete LongText_Dialog;
				return 1;
			}
		}
	}
	return 0;
}
int BlackMoonUI::zyPropertyGrid::propertyItem_Flags_OnClick(PropertyGrid_item* pItem, int index, int isOnButton, int mouseState) {

	if ((pItem->State & 属性状态_只读) != 0) return 1;
	HWND hwnd = (HWND)GetMember(L"hWnd");
	if (isOnButton == 0) {
		return propertyItem_BeginEdit(pItem, index);
	}
	else {
		int selected = (int)SendMessage(hwnd, LVM_GETITEMSTATE, index, LVIS_SELECTED);
		if (selected == LVIS_SELECTED) {
			zyPropretyGrid_HideAll();
			TRegEvent* p = GetRegEvent(L"OnClick");
			if (p) {
				int ret = p->handler<int>(hwnd, pItem, isOnButton);
				if (ret != 0)
					return 1;
			}
			zyDialogBox* _Dialog = new zyDialogBox();
			_Dialog->边框(窗口边框_普通固定边框);
			_Dialog->SetMember(L"pItem", (LONG_PTR)pItem);
			_Dialog->事件_创建完毕(TRegEventCallBack(this, &zyPropertyGrid::propertyItem_Flags_Dialog_OnCraete));
			_Dialog->事件_尺寸被改变(TRegEventCallBack(this, &zyPropertyGrid::propertyItem_Flags_Dialog_OnSize));
			_Dialog->置开始位置(开始位置_居中屏幕);
			_Dialog->Esc关闭(true);
			SetMember(L"_Dialog", (LONG_PTR)_Dialog);
			int ret = (int)_Dialog->载入(GetAncestor(hwnd, GA_ROOT), L"请选择标志位：", POINT{ 0, 0 }, POINT{ 300, 220 },
				WS_VISIBLE | WS_DLGFRAME, WS_EX_DLGMODALFRAME, true);
			if (ret == IDOK) {
				LONG_PTR flagsValue = _Dialog->GetMember(L"Value");
				if (flagsValue) {
					pItem->Value = std::to_wstring( flagsValue);
					//pItem->currentIndex = (int)flagsValue;
					_Dialog->SetMember(L"Value", 0);
				}
				SendMessage(hwnd, LVM_REDRAWITEMS, index, index);
				TRegEvent* p = GetRegEvent(L"OnValueChange");
				if (p) {
					p->handler<int>(hwnd, pItem, 0);
				}
			}
			//销毁对话框后释放内存
			zyStatic* Flags_Lable = (zyStatic*)GetMember(L"Flags_Lable");
			if (Flags_Lable)
				delete Flags_Lable;
			zyTabControl* Flags_Tab = (zyTabControl*)GetMember(L"Flags_Tab");
			if (Flags_Tab)
				delete Flags_Tab;
			zyButton* Flags_BtnCancel = (zyButton*)GetMember(L"Flags_BtnCancel");
			if (Flags_BtnCancel)
				delete Flags_BtnCancel;
			zyButton* Flags_BtnOk = (zyButton*)GetMember(L"Flags_BtnOk");
			if (Flags_BtnOk)
				delete Flags_BtnOk;
			delete _Dialog;
			return 1;
		}
	}
	

	return 0;
}
int BlackMoonUI::zyPropertyGrid::propertyItem_Flags_Dialog_OnCraete(zyForm* form) {
	HWND hWnd = form->getHwnd();
	SendMessage(hWnd, WM_SETICON, 0, 0);
	SendMessage(hWnd, WM_SETICON, 1, 0);

	PropertyGrid_item* pItem = (PropertyGrid_item*)form->GetMember(L"pItem");
	if (!pItem || pItem->Value.empty()) return 0;
	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(pItem->lParam);
	if (!listData) return 0;
	std::vector<FlagsItem>* pListString = listData->pListString;
	std::vector<LPARAM>* pListlParam = listData->pListlParam;
	zyTabControl* Flags_Tab = new zyTabControl();
	Flags_Tab->创建(hWnd, L"选项(&T)");
	SetMember(L"Flags_Tab", (LONG_PTR)Flags_Tab);
	int index = (int)pListString->size();
	std::vector<zyListView>* Flags_List = new std::vector<zyListView>(index);
	SetMember(L"Flags_List", (LONG_PTR)Flags_List);
	int flagsValue = _wtoi(pItem->Value.c_str());
	zyStatic* Flags_Lable = new zyStatic();
	Flags_Lable->创建(hWnd, L"DWORD：" + std::to_wstring(flagsValue), POINT{ 100, 100 }, POINT{ 60, 26 });
	SetMember(L"Flags_Lable", (LONG_PTR)Flags_Lable);

	for (int i = 0; i < index; ++i) {
		std::wstring groupName = (*pListString)[i].pitemName;
		(*Flags_List)[i].事件_检查框状态被改变(TRegEventCallBack(this, &zyPropertyGrid::Flags_ListView_CheckChange));
		(*Flags_List)[i].创建(hWnd, L"", POINT{ 100, 100 }, POINT{ 60, 26 }, 0, LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS);
		(*Flags_List)[i].添加超列扩展风格(LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | LVS_EX_DOUBLEBUFFER | LVS_EX_GRIDLINES);
		(*Flags_List)[i].插入列(-1, L"名称", 200, -1, -1, false);
		(*Flags_List)[i].插入列(-1, L"十进制", 100, -1, -1, false);
		(*Flags_List)[i].插入列(-1, L"十六进制", 100, -1, -1, false);
		(*Flags_List)[i].插入列(-1, L"备注", 180, -1, -1, false);
		if(!(*pListString)[i].pListlItemData) break;
		std::vector<FlagsItemData>* pListlItemData = (*pListString)[i].pListlItemData;
		for (int j = 0; j < pListlItemData->size(); ++j) {
			int itemValue = (*pListlItemData)[j].pitemValue; 
			int index = (*Flags_List)[i].插入表项(-1, (*pListlItemData)[j].pitemName);
			wchar_t hexStr[11] = { 0 };
			wsprintf((LPWSTR)hexStr, L"%08X", itemValue);
			(*Flags_List)[i].置标题(index,1, std::to_wstring(itemValue));
			(*Flags_List)[i].置标题(index, 2, hexStr);
			(*Flags_List)[i].置标题(index, 3, (*pListlItemData)[j].pitemRemark);
			(*Flags_List)[i].置状态图片(index, ((flagsValue & itemValue) == itemValue ? 1 : 0));
		}
		Flags_Tab->添加子夹((zyWindow*)&(*Flags_List)[i], groupName,-1, L"");
	}
	
	zyButton* Flags_BtnOk = new zyButton();
	Flags_BtnOk->创建(hWnd, L"确认(&O)");
	SetMember(L"Flags_BtnOk", (LONG_PTR)Flags_BtnOk);

	zyButton* Flags_BtnCancel = new zyButton();
	Flags_BtnCancel->创建(hWnd, L"取消(&C)");
	SetMember(L"Flags_BtnCancel", (LONG_PTR)Flags_BtnCancel);

	Flags_BtnOk->事件_被单击(TRegEventCallBack(this, &zyPropertyGrid::Flags_BtnOk_事件_被单击));
	Flags_BtnCancel->事件_被单击(TRegEventCallBack(this, &zyPropertyGrid::Flags_BtnCancel_事件_被单击));

	return 0;
}
int BlackMoonUI::zyPropertyGrid::Flags_ListView_CheckChange(HWND hWnd, int 表项索引, int 检查框状态) {
	zyListView* lv = new zyListView();
	zyDialogBox* _Dialog = (zyDialogBox*)GetMember(L"_Dialog");
	zyStatic* Flags_Lable = (zyStatic*)GetMember(L"Flags_Lable");
	/*std::vector<zyListView>* Flags_List = (std::vector<zyListView>*)GetMember(L"Flags_List");
	for (int i = 0; i < Flags_List->size(); ++i) {
		if ((*Flags_List)[i].取窗口句柄()) {
			if ((*Flags_List)[i].取窗口句柄() == hWnd) {
				std::wstring str = (*Flags_List)[i].取标题(表项索引, 1);
				if (!str.empty()) {
					int val = std::stoi(str);
					int flagVal = (int)_Dialog->GetMember(L"Value");
					if (检查框状态 == 0)
						flagVal &= ~val;
					else
						flagVal |= val;
					
					Flags_Lable->置文本(L"DWORD：" + std::to_wstring(flagVal));
					_Dialog->SetMember(L"Value", (LONG_PTR)flagVal);
				}

			}
		}
		else
			break;
	}*/

	if (lv->置窗口句柄(hWnd)) {
		std::wstring str = lv->取标题(表项索引, 1);
		if (!str.empty()) {
			int val = std::stoi(str);
			int flagVal = (int)_Dialog->GetMember(L"Value");
			if (检查框状态 == 0)
				flagVal &= ~val;
			else
				flagVal |= val;

			Flags_Lable->置文本(L"DWORD：" + std::to_wstring(flagVal));
			_Dialog->SetMember(L"Value", (LONG_PTR)flagVal);
		}
	}

	
	delete lv;
	return 0;
}
int BlackMoonUI::zyPropertyGrid::Flags_BtnOk_事件_被单击(HWND hWnd, int ID) {
	std::vector<zyListView>* Flags_List = (std::vector<zyListView>*)GetMember(L"Flags_List");
	zyStatic* Flags_Lable = (zyStatic*)GetMember(L"Flags_Lable");
    int flagsValue = 0;
	int itemValue = 0;
	for (int i = 0; i < Flags_List->size(); ++i) {
		int itemCount =(*Flags_List)[i].取表项数();
        for (int j = 0; j < itemCount; ++j) {
			int state = (*Flags_List)[i].取状态图片(j);
			if (state != 0) {
				itemValue = std::stoi((*Flags_List)[i].取标题(j, 1));
				flagsValue |= itemValue;
			}
		}
		itemValue = std::stoi((*Flags_List)[i].取标题(i, 1));
	}
	Flags_Lable->置文本(L"DWORD：" + std::to_wstring(flagsValue));
	zyDialogBox* _Dialog = (zyDialogBox*)GetMember(L"_Dialog");
	_Dialog->SetMember(L"Value", (LONG_PTR)flagsValue);
	_Dialog->返回值(IDOK);
	_Dialog->销毁();
	return 0;
}
int BlackMoonUI::zyPropertyGrid::Flags_BtnCancel_事件_被单击(HWND hWnd, int ID) {
	zyDialogBox* _Dialog = (zyDialogBox*)GetMember(L"_Dialog");
	_Dialog->返回值(IDOK);
	_Dialog->销毁();
	return 0;
}
int BlackMoonUI::zyPropertyGrid::propertyItem_Flags_Dialog_OnSize(HWND hWnd, WORD cx, WORD cy) {
	zyTabControl* Flags_Tab = (zyTabControl*)GetMember(L"Flags_Tab");
	zyButton* Flags_BtnCancel = (zyButton*)GetMember(L"Flags_BtnCancel");
	zyButton* Flags_BtnOk = (zyButton*)GetMember(L"Flags_BtnOk");
	zyStatic* Flags_Lable = (zyStatic*)GetMember(L"Flags_Lable");
	Flags_Lable->moveWindow(10, cy - 30, 150, 24);
	Flags_Tab->moveWindow(5, 1, cx - 10, cy - 35, 0);
	Flags_BtnCancel->moveWindow(cx - 87, cy - 40 + 10, 80, 24);
	Flags_BtnOk->moveWindow(Flags_BtnCancel->左边() - 100 - 5, cy - 40 + 10, 80, 24);

	return 0;
}
void BlackMoonUI::zyPropertyGrid::_init(HWND hWnd, const std::wstring& 参数_列头标题1, const std::wstring& 参数_列头标题2) {
	// 清理旧资源
	if (zyLmageList* pOldImgList = reinterpret_cast<zyLmageList*>(GetMember(L"pImageList"))) {
		pOldImgList->getObject()->release();
	}
	if (zyEditBox* pOldEdit = reinterpret_cast<zyEditBox*>(GetMember(L"pEdit"))) {
		delete pOldEdit;
	}
	if (zyWidget* pOldListWin = reinterpret_cast<zyWidget*>(GetMember(L"pListWindow"))) {
		delete pOldListWin;
	}
	if (zyListBox* pOldList = reinterpret_cast<zyListBox*>(GetMember(L"pList"))) {
		delete pOldList;
	}
	if (auto* pOldProps = reinterpret_cast<std::vector<PropertyGrid_item*>*>(GetMember(L"Propertys"))) {
		delete pOldProps;
	}

	// 初始化样式属性
	constexpr int rowHeight = 20;
	SetMember(L"GridBackColor", zyRGB2ARGB(15790320, 255));
	SetMember(L"GridTextColor", 0x000000L);
	SetMember(L"GridSelBackColor", zyRGB2ARGB(GetSysColor(COLOR_HIGHLIGHT), 255));
	SetMember(L"GridSelTextColor", zyRGB2ARGB(0, 255));

	// 创建行高图片组
	zyLmageList* pImageList = new zyLmageList();
	pImageList->Create(rowHeight, rowHeight);
	pImageList->getObject()->addRef();
	SetMember(L"pImageList", reinterpret_cast<LONG_PTR>(pImageList));
	SendMessage(hWnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)pImageList->取句柄());

	// 配置列表控件
	SendMessage(hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
		LVS_EX_SUBITEMIMAGES | LVS_EX_INFOTIP | LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT);
	SetMember(L"Propertys", reinterpret_cast<LONG_PTR>(new std::vector<PropertyGrid_item*>()));

	// 清空列表数据
	SendMessage(hWnd, LVM_DELETEALLITEMS, 0, 0);
	while (SendMessage(hWnd, LVM_DELETECOLUMN, 0, 0) != FALSE) {} // 更安全的列删除方式

	// 插入双列
	LVCOLUMN col = { LVCF_FMT | LVCF_TEXT | LVCF_WIDTH };
	col.fmt = LVCFMT_LEFT;
	col.cx = 100;
	if(!参数_列头标题1.empty())
		col.pszText = (LPWSTR)参数_列头标题1.c_str();
	SendMessage(hWnd, LVM_INSERTCOLUMNW, 0, reinterpret_cast<LPARAM>(&col));
	if (!参数_列头标题2.empty())
		col.pszText = (LPWSTR)参数_列头标题2.c_str();
	SendMessage(hWnd, LVM_INSERTCOLUMNW, 1, reinterpret_cast<LPARAM>(&col));
	HWND m_hHeader = ListView_GetHeader(hWnd); // 获取表头句柄
	SetMember(L"hHeader", reinterpret_cast<LONG_PTR>(m_hHeader));
	// 创建编辑控件
	zyEditBox* pEdit = new zyEditBox();
	pEdit->边框(控件边框_无边框);
	pEdit->通用事件_窗口消息(TRegEventCallBack(this, &zyPropertyGrid::propertyItem_Edit_Msg));
	pEdit->添加ZY窗口风格(ZY窗口风格_需要回车键);
	pEdit->垂直居中(TRUE);
	pEdit->创建(hWnd, L"", POINT{ 0, 0 }, POINT{ 100, rowHeight + 8 }, 0, ES_AUTOHSCROLL | WS_TABSTOP);
	pEdit->置属性(L"pListView", this);
	pEdit->可视(FALSE);
	//SetFocus(pEdit->getHwnd()); // 是编辑控件的句柄
	pEdit->getObject()->addRef();
	SetMember(L"pEdit", reinterpret_cast<LONG_PTR>(pEdit));

	// 创建下拉容器
	zyWidget* pListWindow = new zyWidget();
	pListWindow->边框(窗口边框_无边框);
	//pListWindow->通用事件_窗口消息(TRegEventCallBack(this, &zyPropertyGrid::propertyItem_ListWindow_Msg));
	pListWindow->创建(GetAncestor(hWnd, GA_ROOT), L"", POINT{ 0, 0 }, POINT{ 100, 100 }, WS_POPUP);
	pListWindow->置属性(L"pListView", this);
	pListWindow->getObject()->addRef();
	SetMember(L"pListWindow", reinterpret_cast<LONG_PTR>(pListWindow));

	// 创建列表框
	zyListBox* pList = new zyListBox();
	pList->通用事件_窗口消息(TRegEventCallBack(this, &zyPropertyGrid::propertyItem_list_Msg));
	pList->事件_列表项被选择(TRegEventCallBack(this, &zyPropertyGrid::propertyItem_List_OnSelected));
	pList->创建(pListWindow->取窗口句柄());
	pList->置属性(L"pListView", this);
	pList->getObject()->addRef();
	SetMember(L"pList", reinterpret_cast<LONG_PTR>(pList));

	// 触发布局更新
	RECT rc;
	GetClientRect(hWnd, &rc);
	SendMessage(hWnd, WM_SIZE, 0, MAKEWPARAM(rc.right - rc.left, rc.bottom - rc.top));
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::_InsertProperty(int index, PropertyGrid_item* parent, const std::wstring& name, int type, 
	int state, LPARAM lParam,const std::wstring& Value) {
	// 获取属性列表
	std::vector<PropertyGrid_item*>* Propertys = (std::vector<PropertyGrid_item*>*)(GetMember(L"Propertys"));
	if (!Propertys) {
		Propertys = new std::vector<PropertyGrid_item*>();
		SetMember(L"Propertys", reinterpret_cast<LONG_PTR>(Propertys)); //return nullptr;
	}
	int parentState = 0;
	int parentLevel = 0;

	// 处理父项逻辑
	if (parent) {
		parentState = parent->State;
		parentLevel = parent->Level + 1; // 子项层级 = 父项层级 + 1

		// 如果父项没有子项容器，则创建
		if (!parent->Childs) {
			parent->Childs = new std::vector<PropertyGrid_item*>();
		}
		Propertys = parent->Childs; // 切换到父项的子项列表
	}

	// 处理插入位置
	int count = static_cast<int>(Propertys->size());
	if (index < 0 || index > count) index = count;

	// 创建新属性项
	PropertyGrid_item* pitem = new PropertyGrid_item();
	pitem->Name = name;
	pitem->Type = type;
	pitem->State = state;
	pitem->TextColor = zyRGB2ARGB(0, 255); // 黑色
	pitem->Level = parentLevel;
	if (type == 属性类型_标志位 || type == 属性类型_列表) {
		pitem->lParam = lParam;
	}
	else{
		pitem->userData = lParam;
	}
	
	pitem->Parent = parent;
	pitem->Childs = new std::vector<PropertyGrid_item*>(); // 初始化子项容器
	if(!Value.empty())
		pitem->Value = Value;
	// 插入到属性列表
	Propertys->insert(Propertys->begin() + index, pitem);

	// 获取列表视图句柄
	HWND hWnd = (HWND)(GetMember(L"hWnd"));

	// 处理顶层项插入逻辑
	if (!parent) {
		if (index > 0) {
			// 查找所有顶层项
			std::vector<int> topItems;
			int itemCount = static_cast<int>(SendMessage(hWnd, LVM_GETITEMCOUNT, 0, 0));
			for (int i = 0; i < itemCount; i++) {
				LVITEM item = { 0 };
				item.mask = LVIF_PARAM;
				item.iItem = i;
				if (SendMessage(hWnd, LVM_GETITEM, 0, reinterpret_cast<LPARAM>(&item))) {
					PropertyGrid_item* currentItem = reinterpret_cast<PropertyGrid_item*>(item.lParam);
					if (currentItem && !currentItem->Parent) {
						topItems.push_back(i); // 记录顶层项索引
					}
				}
			}

			// 计算实际插入位置
			count = static_cast<int>(topItems.size());
			if (index >= count) {
				// 插入到最后一个顶层项之后
				int lastTopIndex = topItems[count-1];
				LVITEM item = { 0 };
				item.mask = LVIF_PARAM;
				item.iItem = lastTopIndex;
				if (SendMessage(hWnd, LVM_GETITEM, 0, reinterpret_cast<LPARAM>(&item))) {
					PropertyGrid_item* lastTopItem = reinterpret_cast<PropertyGrid_item*>(item.lParam);
					if (lastTopItem && (lastTopItem->State & 属性状态_扩展)) {
						// 如果最后一个顶层项是展开状态，插入到其子项之后
						int childCount = static_cast<int>(lastTopItem->Childs->size());
						index = lastTopIndex + childCount + 1;
					}
					else {
						// 否则插入到最后一个顶层项之后
						index = lastTopIndex + 1;
					}
				}
			}
			else {
				// 插入到指定顶层项的位置
				index = topItems[index];
			}
		}

		// 插入到列表视图
		LVITEM lvitem = { 0 };//LVIF_STATE 表示state成员有效 鼠标移动时会触发，否则可能触发不及时导致绘制不完整
		lvitem.mask = LVIF_PARAM | LVIF_TEXT | LVIF_STATE ;
		lvitem.iItem = index;
		lvitem.iSubItem = 0;
		lvitem.pszText = const_cast<LPWSTR>(pitem->Name.c_str());
		lvitem.cchTextMax = static_cast<int>(pitem->Name.size());
		//lvitem.iIndent = parentLevel;//LVIF_INDENT  表示iIndent成员有效 主要用于设置列表项的缩进级别
		lvitem.lParam = reinterpret_cast<LPARAM>(pitem);

		if (SendMessage(hWnd, LVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&lvitem)) == -1) {
			delete pitem; // 插入失败，释放内存
			return nullptr;
		}
	}
	// 处理子项插入逻辑
	else if (parentState & 属性状态_扩展) {
		// 查找父项在列表中的位置
		LVFINDINFO lvfi = { 0 };
		lvfi.flags = LVFI_PARAM;
		lvfi.lParam = reinterpret_cast<LPARAM>(parent);
		int parentIndex = static_cast<int>(SendMessage(hWnd, LVM_FINDITEM, -1, reinterpret_cast<LPARAM>(&lvfi)));
		if (parentIndex == -1) return pitem; // 父项未找到，直接返回

		// 计算子项插入位置
		index = parentIndex + index + 1;

		// 插入到列表视图
		LVITEM lvitem = { 0 };//LVIF_STATE 表示state成员有效 鼠标移动时会触发，否则可能触发不及时导致绘制不完整
		lvitem.mask = LVIF_PARAM | LVIF_TEXT | LVIF_STATE ;
		lvitem.iItem = index;
		lvitem.iSubItem = 0;
		lvitem.pszText = const_cast<LPWSTR>(pitem->Name.c_str());
		lvitem.cchTextMax = static_cast<int>(pitem->Name.size());
		//lvitem.iIndent = parentLevel;//LVIF_INDENT  表示iIndent成员有效 主要用于设置列表项的缩进级别
		lvitem.lParam = reinterpret_cast<LPARAM>(pitem);

		if (SendMessage(hWnd, LVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&lvitem)) == -1) {
			delete pitem; // 插入失败，释放内存
			return nullptr;
		}
	}

	return pitem;
}
BOOL BlackMoonUI::zyPropertyGrid::创建(HWND 参数_父窗口, const std::wstring& 参数_标题, POINT 参数_位置, POINT 参数_尺寸, int 参数_ID, int 参数_窗口风格, 
	int 参数_扩展风格, const std::wstring& 参数_列头标题1, const std::wstring& 参数_列头标题2)
{
	if (参数_ID == NULL)
		参数_ID = 黑月默认ID();
	if (参数_列头标题1.empty() || 参数_列头标题2.empty())
		参数_窗口风格 = LVS_NOCOLUMNHEADER;
	if (参数_扩展风格 == 0)
		参数_扩展风格 = WS_EX_CLIENTEDGE;	
	bool b = _CreateCtrol(参数_父窗口, 参数_标题, 参数_位置, 参数_尺寸, 参数_ID, 参数_窗口风格 /* | LVS_NOCOLUMNHEADER*/ | LVS_REPORT | 
		LVS_SINGLESEL | LVS_SHOWSELALWAYS | WS_CLIPCHILDREN, 参数_扩展风格, L"SysListView32");
	if (b) {
		_init(getHwnd(), 参数_列头标题1, 参数_列头标题2);
	}
	return b;
}
BOOL BlackMoonUI::zyPropertyGrid::创建(zyWindow& 参数_父窗口, const std::wstring& 参数_标题, POINT 参数_位置, POINT 参数_尺寸, int 参数_ID, int 参数_窗口风格, 
	int 参数_扩展风格, const std::wstring& 参数_列头标题1, const std::wstring& 参数_列头标题2)
{
	if (参数_ID == NULL)
		参数_ID = 黑月默认ID();
	if (参数_列头标题1.empty() || 参数_列头标题2.empty())
		参数_窗口风格 = LVS_NOCOLUMNHEADER;
	if (参数_扩展风格 == 0)
		参数_扩展风格 = WS_EX_CLIENTEDGE;
	bool b = _CreateCtrol(参数_父窗口.getHwnd(), 参数_标题, 参数_位置, 参数_尺寸, 参数_ID, 参数_窗口风格 /*| LVS_NOCOLUMNHEADER */ | LVS_REPORT | 
		LVS_SINGLESEL | LVS_SHOWSELALWAYS | WS_CLIPCHILDREN, 参数_扩展风格, L"SysListView32");
	if (b) {
		_init(getHwnd(), 参数_列头标题1, 参数_列头标题2);
	}
	return b;
}
void BlackMoonUI::zyPropertyGrid::背景色(ARGB 参数_背景色)
{
	SetMember(L"GridBackColor", 参数_背景色);
}
ARGB BlackMoonUI::zyPropertyGrid::背景色()
{
	return (ARGB)GetMember(L"GridBackColor");
}
bool BlackMoonUI::zyPropertyGrid::绑定(HWND 参数_父窗口, int 参数_资源ID, bool 参数_使用默认字体) {//成功返回真，失败返回假。
	HWND hwnd = GetDlgItem(参数_父窗口, 参数_资源ID);
	if (hwnd != 0) {
		int Style = (int)GetWindowLongPtr(hwnd, GWL_STYLE);
		Style = Style & ~(LVS_SMALLICON | LVS_LIST | LVS_AUTOARRANGE | LVS_EDITLABELS | LVS_NOSCROLL);
		Style = Style | LVS_NOCOLUMNHEADER | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS;
		SetWindowLongPtr(hwnd, GWL_STYLE, Style);
		_init(hwnd);
		if (hwnd != 0 && 参数_使用默认字体) {
			SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
		}
	}
	return _BindWindow(hwnd);
}
bool BlackMoonUI::zyPropertyGrid::绑定窗口句柄(HWND 参数_窗口句柄) {//成功返回真，失败返回假。
	if (IsWindow(参数_窗口句柄) != 0) {
		int Style = (int)GetWindowLongPtr(参数_窗口句柄, GWL_STYLE);
		Style = Style & ~(LVS_SMALLICON | LVS_LIST | LVS_AUTOARRANGE | LVS_EDITLABELS | LVS_NOSCROLL);
		Style = Style | LVS_NOCOLUMNHEADER | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS;
		SetWindowLongPtr(参数_窗口句柄, GWL_STYLE, Style);
		_init(参数_窗口句柄);
	}
	return _BindWindow(参数_窗口句柄);
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::插入项目_分组(int 参数_索引, const std::wstring& 参数_名称,
	LPARAM 参数_项目数值) {//成功返回项目句柄，失败返回0
	if (参数_索引 == 0) {
		参数_索引 = -1;
	}
	PropertyGrid_item* pItem = _InsertProperty(参数_索引, 0, 参数_名称, 属性类型_分组, 属性状态_扩展, 参数_项目数值);
	if (pItem == nullptr) {
		return 0;
	}
	//int value = propertyItem_Group_New (pItem);
	//if (value == 0) {
		//zyPropretyGrid_FreePropertyItem (pItem);
	//	return 0;
	//}
	//pItem->Value = value;
	return pItem;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::插入项目_文本(int 参数_索引, PropertyGrid_item* 参数_父项目句柄 ,
	const std::wstring& 参数_名称,const std::wstring& 参数_值,LPARAM 参数_项目数值) {//成功返回项目句柄，失败返回0
	if (参数_索引 == 0) {
		参数_索引 = -1;
	}
	PropertyGrid_item* pItem = _InsertProperty(参数_索引, 参数_父项目句柄, 参数_名称, 属性类型_文本, 属性状态_收缩, 
		参数_项目数值, 参数_值);
	if (pItem == nullptr) {
		return 0;
	}
	return pItem;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::插入项目_长文本(int 参数_索引, PropertyGrid_item* 参数_父项目句柄,
	const std::wstring& 参数_名称, const std::wstring& 参数_值, LPARAM 参数_项目数值) {//成功返回项目句柄，失败返回0
	if (参数_索引 == 0) {
		参数_索引 = -1;
	}
	PropertyGrid_item* pItem = _InsertProperty(参数_索引, 参数_父项目句柄, 参数_名称, 属性类型_长文本, 属性状态_收缩, 
		参数_项目数值, 参数_值);
	if (pItem == nullptr) {
		return 0;
	}
	return pItem;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::插入项目_列表(int 参数_索引, PropertyGrid_item* 参数_父项目句柄, 
	const std::wstring& 参数_名称, LPARAM 参数_项目数值) {//成功返回项目句柄，失败返回0
	if (参数_索引 == 0) {
		参数_索引 = -1;
	}

	// 为每个列表项创建独立的数据存储
	ListItemData* listData = new ListItemData();
	listData->pListString = new std::vector<std::wstring>();
	listData->pListlParam = new std::vector<LPARAM>();

	PropertyGrid_item* pItem = _InsertProperty(参数_索引, 参数_父项目句柄, 参数_名称, 属性类型_列表, 属性状态_收缩, reinterpret_cast<LPARAM>(listData));
		
	if (pItem == nullptr) {
		delete listData->pListString;
		delete listData->pListlParam;
		delete listData;
		return nullptr;
	}
	pItem->userData = 参数_项目数值; // 直接赋值
	return pItem;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::插入项目_逻辑(int 参数_索引, PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_名称,
	int 参数_值, LPARAM 参数_项目数值) {//成功返回项目句柄，失败返回0
	if (参数_索引 == 0) {
		参数_索引 = -1;
	}
	// 检查是否已存在列表数据，避免重复创建
	std::vector<std::wstring>* pListString = (std::vector<std::wstring>*)GetMember(L"pListStringbool");
	std::vector<LPARAM>* pListlParam = (std::vector<LPARAM>*)GetMember(L"pListlParambool");

	if (!pListString || !pListlParam) {
		pListString = new std::vector<std::wstring>(2);
		(*pListString)[0] = L"假";
		(*pListString)[1] = L"真";
		SetMember(L"pListStringbool", (LONG_PTR)pListString);

		pListlParam = new std::vector<LPARAM>(2);
		(*pListlParam)[0] = 0;
		(*pListlParam)[1] = 1;
		SetMember(L"pListlParambool", (LONG_PTR)pListlParam);
	}
	PropertyGrid_item* pItem = _InsertProperty(参数_索引, 参数_父项目句柄, 参数_名称, 属性类型_逻辑, 属性状态_收缩, 参数_项目数值);
	if (pItem == nullptr) {
		return nullptr;
	}
	pItem->currentIndex = 参数_值; // 直接赋值
	return pItem;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::插入项目_标志位(int 参数_索引, PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_名称,
	int 参数_值, LPARAM 参数_项目数值)
{
	if (参数_索引 == 0) {
		参数_索引 = -1;
	}
	// 为每个列表项创建独立的数据存储
	FlagsListItemData* listData = new FlagsListItemData();
	listData->pListString = new std::vector<FlagsItem>();
	listData->pListlParam = new std::vector<LPARAM>();
	//listData->pListlItemData = new std::vector<FlagsItemData>();
	PropertyGrid_item* pItem = _InsertProperty(参数_索引, 参数_父项目句柄, 参数_名称, 属性类型_标志位, 属性状态_收缩, 
		reinterpret_cast<LPARAM>(listData),std::to_wstring(参数_值));
	if (pItem == nullptr) {
		// 修复：释放分配的内存
		for (auto& group : *listData->pListString) {
			delete group.pListlItemData;
		}
		delete listData->pListString;
		delete listData->pListlParam;
		delete listData;
		return nullptr;
	}
	//pItem->currentIndex = 参数_值; // 直接赋值
	FlagsItem flagsData = { 参数_名称 ,nullptr };
	listData->pListString->push_back(flagsData);
	listData->pListlParam->push_back(参数_项目数值);
	return pItem;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::插入项目_颜色(int 参数_索引, PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_名称,
	int 参数_值, LPARAM 参数_项目数值) {//成功返回项目句柄，失败返回0
	if (参数_索引 == 0) {
		参数_索引 = -1;
	}
	PropertyGrid_item* pItem = _InsertProperty(参数_索引, 参数_父项目句柄, 参数_名称, 属性类型_颜色, 属性状态_收缩, 
		参数_项目数值,std::to_wstring(参数_值));
	if (pItem == nullptr) {
		return 0;
	}
	//pItem->currentIndex = 参数_值; // 直接赋值

	return pItem;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::插入项目_字体(int 参数_索引, PropertyGrid_item* 参数_父项目句柄,
	const std::wstring& 参数_名称,const std::wstring& 参数_值, LPARAM 参数_项目数值) {//成功返回项目句柄，失败返回0
	if (参数_索引 == 0) {
		参数_索引 = -1;
	}
	PropertyGrid_item* pItem = _InsertProperty(参数_索引, 参数_父项目句柄, 参数_名称, 属性类型_字体, 属性状态_收缩, 
		参数_项目数值, 参数_值);
	if (pItem == nullptr) {
		return 0;
	}
	//pItem->currentIndex = 参数_值; // 直接赋值

	return pItem;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::插入项目_图片(int 参数_索引, PropertyGrid_item* 参数_父项目句柄, 
	const std::wstring& 参数_名称,const std::wstring& 参数_值, LPARAM 参数_项目数值) {//成功返回项目句柄，失败返回0
	if (参数_索引 == 0) {
		参数_索引 = -1;
	}
	PropertyGrid_item* pItem = _InsertProperty(参数_索引, 参数_父项目句柄, 参数_名称, 属性类型_图片, 属性状态_收缩,
		参数_项目数值, 参数_值);
	if (pItem == nullptr) {
		return 0;
	}
	//pItem->currentIndex = 参数_值; // 直接赋值

	return pItem;
}

int BlackMoonUI::zyPropertyGrid::列表_添加项目(PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_名称, LPARAM 参数_项目数值) {//成功返回项目句柄，失败返回0
	if (参数_父项目句柄 == nullptr || 参数_父项目句柄->Type != 属性类型_列表) {
		return -1;
	}

	// 从列表项的lParam中获取独立数据
	ListItemData* listData = reinterpret_cast<ListItemData*>(参数_父项目句柄->lParam);
	if (!listData) return -1;

	listData->pListString->push_back(参数_名称);
	listData->pListlParam->push_back(参数_项目数值);
	return static_cast<int>(listData->pListlParam->size());
}
// 获取列表项目总数
int BlackMoonUI::zyPropertyGrid::列表_取项目总数(PropertyGrid_item* 参数_父项目句柄)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_列表)
		return -1;

	ListItemData* listData = reinterpret_cast<ListItemData*>(参数_父项目句柄->lParam);
	return listData ? static_cast<int>(listData->pListString->size()) : -1;
}

// 获取指定索引的列表文本
std::wstring BlackMoonUI::zyPropertyGrid::列表_取项目文本(PropertyGrid_item* 参数_父项目句柄, int 参数_索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_列表)
		return L"";

	ListItemData* listData = reinterpret_cast<ListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_索引 < 0 || 参数_索引 >= static_cast<int>(listData->pListString->size()))
		return L"";

	return listData->pListString->at(参数_索引);
}

// 获取指定索引的列表数值
LPARAM BlackMoonUI::zyPropertyGrid::列表_取项目数值(PropertyGrid_item* 参数_父项目句柄, int 参数_索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_列表)
		return 0;

	ListItemData* listData = reinterpret_cast<ListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_索引 < 0 || 参数_索引 >= static_cast<int>(listData->pListlParam->size()))
		return 0;

	return listData->pListlParam->at(参数_索引);
}

// 删除指定索引的列表项
bool BlackMoonUI::zyPropertyGrid::列表_删除项目(PropertyGrid_item* 参数_父项目句柄, int 参数_索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_列表)
		return false;

	ListItemData* listData = reinterpret_cast<ListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_索引 < 0 || 参数_索引 >= static_cast<int>(listData->pListString->size()))
		return false;

	// 删除元素
	listData->pListString->erase(listData->pListString->begin() + 参数_索引);
	listData->pListlParam->erase(listData->pListlParam->begin() + 参数_索引);

	// 更新显示
	int index = _GetItemIndex(参数_父项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}

// 清空所有列表项
bool BlackMoonUI::zyPropertyGrid::列表_清空项目(PropertyGrid_item* 参数_父项目句柄)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_列表)
		return false;

	ListItemData* listData = reinterpret_cast<ListItemData*>(参数_父项目句柄->lParam);
	if (!listData)
		return false;

	listData->pListString->clear();
	listData->pListlParam->clear();

	// 更新显示
	int index = _GetItemIndex(参数_父项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}

// 设置列表项文本
bool BlackMoonUI::zyPropertyGrid::列表_置项目文本(PropertyGrid_item* 参数_父项目句柄, int 参数_索引, const std::wstring& 参数_文本)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_列表)
		return false;

	ListItemData* listData = reinterpret_cast<ListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_索引 < 0 || 参数_索引 >= static_cast<int>(listData->pListString->size()))
		return false;

	listData->pListString->at(参数_索引) = 参数_文本;

	// 更新显示
	int index = _GetItemIndex(参数_父项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}

// 设置列表项数值
bool BlackMoonUI::zyPropertyGrid::列表_置项目数值(PropertyGrid_item* 参数_父项目句柄, int 参数_索引, LPARAM 参数_数值)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_列表)
		return false;

	ListItemData* listData = reinterpret_cast<ListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_索引 < 0 || 参数_索引 >= static_cast<int>(listData->pListlParam->size()))
		return false;

	listData->pListlParam->at(参数_索引) = 参数_数值;

	// 更新显示
	int index = _GetItemIndex(参数_父项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}
int BlackMoonUI::zyPropertyGrid::标志位_添加分组(PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_分组名称) {//成功返回项目句柄，失败返回0
	if (参数_父项目句柄 == nullptr || 参数_父项目句柄->Type != 属性类型_标志位) {
		return -1;
	}

	// 从列表项的lParam中获取独立数据
	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData) return -1;
	FlagsItem flagsData = { 参数_分组名称 ,nullptr };
	listData->pListString->push_back(flagsData);
	listData->pListlParam->push_back(0);
	return static_cast<int>(listData->pListString->size());
}
int BlackMoonUI::zyPropertyGrid::标志位_添加项目(PropertyGrid_item* 参数_父项目句柄, int 参数_分组索引, const std::wstring& 参数_名称,
	int 参数_值, const std::wstring& 参数_备注) {
	if (参数_父项目句柄 == nullptr || 参数_父项目句柄->Type != 属性类型_标志位) {
		return -1;
	}

	// 获取独立数据
	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData) return -1;

	if (参数_分组索引 < 0 || static_cast<size_t>(参数_分组索引) >= listData->pListString->size()) {
		return -1;
	}

	std::vector<FlagsItemData>* item = (*listData->pListString)[参数_分组索引].pListlItemData;
	if (item == nullptr) {
		item = new std::vector<FlagsItemData>();
	}
	FlagsItemData data = { 参数_名称 ,参数_值,参数_备注 };
	item->push_back(data);
	(*listData->pListString)[参数_分组索引].pListlItemData = item;

	return static_cast<int>(listData->pListString->size());
}
// 获取标志位项目名称
std::wstring BlackMoonUI::zyPropertyGrid::标志位_取项目名称(
	PropertyGrid_item* 参数_父项目句柄,int 参数_分组索引,int 参数_项目索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_标志位)
		return L"";

	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_分组索引 < 0 || 参数_分组索引 >= static_cast<int>(listData->pListString->size()))
		return L"";

	FlagsItem& group = listData->pListString->at(参数_分组索引);
	if (!group.pListlItemData || 参数_项目索引 < 0 || 参数_项目索引 >= static_cast<int>(group.pListlItemData->size()))
		return L"";

	return group.pListlItemData->at(参数_项目索引).pitemName;
}

// 获取标志位项目备注
std::wstring BlackMoonUI::zyPropertyGrid::标志位_取项目备注(
	PropertyGrid_item* 参数_父项目句柄,int 参数_分组索引,int 参数_项目索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_标志位)
		return L"";

	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_分组索引 < 0 || 参数_分组索引 >= static_cast<int>(listData->pListString->size()))
		return L"";

	FlagsItem& group = listData->pListString->at(参数_分组索引);
	if (!group.pListlItemData || 参数_项目索引 < 0 || 参数_项目索引 >= static_cast<int>(group.pListlItemData->size()))
		return L"";

	return group.pListlItemData->at(参数_项目索引).pitemRemark;
}

// 获取标志位项目数值
LPARAM BlackMoonUI::zyPropertyGrid::标志位_取项目数值(
	PropertyGrid_item* 参数_父项目句柄,int 参数_分组索引,int 参数_项目索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_标志位)
		return -1;

	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_分组索引 < 0 || 参数_分组索引 >= static_cast<int>(listData->pListString->size()))
		return -1;

	FlagsItem& group = listData->pListString->at(参数_分组索引);
	if (!group.pListlItemData || 参数_项目索引 < 0 || 参数_项目索引 >= static_cast<int>(group.pListlItemData->size()))
		return -1;

	return group.pListlItemData->at(参数_项目索引).pitemValue;
}

// 删除指定标志位项目
bool BlackMoonUI::zyPropertyGrid::标志位_删除项目(
	PropertyGrid_item* 参数_父项目句柄,int 参数_分组索引,int 参数_项目索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_标志位)
		return false;

	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_分组索引 < 0 || 参数_分组索引 >= static_cast<int>(listData->pListString->size()))
		return false;

	FlagsItem& group = listData->pListString->at(参数_分组索引);
	if (!group.pListlItemData || 参数_项目索引 < 0 || 参数_项目索引 >= static_cast<int>(group.pListlItemData->size()))
		return false;

	// 删除项目
	group.pListlItemData->erase(group.pListlItemData->begin() + 参数_项目索引);

	// 更新显示
	int index = _GetItemIndex(参数_父项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}

// 清空标志位分组项目
bool BlackMoonUI::zyPropertyGrid::标志位_清空项目(PropertyGrid_item* 参数_父项目句柄,int 参数_分组索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_标志位)
		return false;

	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_分组索引 < 0 || 参数_分组索引 >= static_cast<int>(listData->pListString->size()))
		return false;

	FlagsItem& group = listData->pListString->at(参数_分组索引);
	if (group.pListlItemData) {
		group.pListlItemData->clear();
	}

	// 更新显示
	int index = _GetItemIndex(参数_父项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}

// 设置标志位分组名称
bool BlackMoonUI::zyPropertyGrid::标志位_置分组名称(PropertyGrid_item* 参数_父项目句柄,int 参数_分组索引,
	const std::wstring& 参数_新名称)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_标志位)
		return false;

	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_分组索引 < 0 || 参数_分组索引 >= static_cast<int>(listData->pListString->size()))
		return false;

	listData->pListString->at(参数_分组索引).pitemName = 参数_新名称;

	// 更新显示
	int index = _GetItemIndex(参数_父项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}

// 获取标志位分组名称
std::wstring BlackMoonUI::zyPropertyGrid::标志位_取分组名称(PropertyGrid_item* 参数_父项目句柄,int 参数_分组索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_标志位)
		return L"";

	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_分组索引 < 0 || 参数_分组索引 >= static_cast<int>(listData->pListString->size()))
		return L"";

	return listData->pListString->at(参数_分组索引).pitemName;
}

// 删除标志位分组
bool BlackMoonUI::zyPropertyGrid::标志位_删除分组(PropertyGrid_item* 参数_父项目句柄,int 参数_分组索引)
{
	if (!参数_父项目句柄 || 参数_父项目句柄->Type != 属性类型_标志位)
		return false;

	FlagsListItemData* listData = reinterpret_cast<FlagsListItemData*>(参数_父项目句柄->lParam);
	if (!listData || 参数_分组索引 < 0 || 参数_分组索引 >= static_cast<int>(listData->pListString->size()))
		return false;
	// 确保 pListString 和 pListlParam 大小一致
	if (listData->pListlParam == nullptr || listData->pListString->size() != listData->pListlParam->size())
		return false;
	FlagsItem& group = listData->pListString->at(参数_分组索引);
	// 显式检查并释放 pListlItemData
	if (group.pListlItemData != nullptr) {
		delete group.pListlItemData;
		group.pListlItemData = nullptr;
	}
	// 删除分组及关联数据
	listData->pListString->erase(listData->pListString->begin() + 参数_分组索引);
	listData->pListlParam->erase(listData->pListlParam->begin() + 参数_分组索引);

	// 更新显示
	int index = _GetItemIndex(参数_父项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}
int BlackMoonUI::zyPropertyGrid::_GetItemIndex(PropertyGrid_item* 参数_项目句柄) {//获取属性在控件中的索引，如果在收缩状态，则返回-1
	LVFINDINFO lvfi = {0};
	lvfi.flags = LVFI_PARAM;
	lvfi.lParam = (LPARAM)参数_项目句柄;
	int index = (int)发送消息(LVM_FINDITEMW, -1, (LPARAM)&lvfi);
	return index;
}

bool BlackMoonUI::zyPropertyGrid::删除项目(PropertyGrid_item* 参数_项目句柄) {//删除指定项目
	std::vector<PropertyGrid_item*>* pChilds = nullptr;
	if (参数_项目句柄 == nullptr) {
		return false;
	}
	if (参数_项目句柄->Type == 属性类型_列表) {
		ListItemData* listData = reinterpret_cast<ListItemData*>(参数_项目句柄->lParam);
		if (listData) {
			delete listData;
		}
	}
	int index = _GetItemIndex(参数_项目句柄);
	PropertyGrid_item* parent = 参数_项目句柄->Parent;
	if (parent == nullptr) {
		pChilds = (std::vector<PropertyGrid_item*>*)GetMember(L"Propertys");
	}
	else {
		pChilds = (std::vector<PropertyGrid_item*>*)parent->Childs;
	}
	if (pChilds == nullptr) {
		return false;
	}
	//if (Array_RemoveFromValue(pChilds, 参数_项目句柄) == false) {
	//	return false;
	//}
	//zyPropretyGrid_FreePropertyItem(参数_项目句柄);
	if (index != -1) {
		发送消息(LVM_DELETEITEM, index, 0);
	}
	return true;
}
void BlackMoonUI::zyPropertyGrid::清空() {//删除全部项目
	发送消息(LVM_DELETEALLITEMS, 0, 0);
	// 递归释放属性项及其子项
	std::vector<PropertyGrid_item*>* Propertys = (std::vector<PropertyGrid_item*>*)GetMember(L"Propertys");
	if (Propertys != nullptr) {
		for (auto* pItem : *Propertys) {
			DeletePropertyItem(pItem);
		}
		delete Propertys;
		SetMember(L"Propertys", 0);
	}
}
bool BlackMoonUI::zyPropertyGrid::置项目值_文本(PropertyGrid_item* 参数_项目句柄, const std::wstring& 参数_文本) {//项目赋值 
	if (参数_项目句柄 == nullptr) {
		return false;
	}
	int type = 参数_项目句柄->Type;
	if (type != 属性类型_文本 && type != 属性类型_长文本 && type != 属性类型_图片) {
		return false;
	}
	参数_项目句柄->Value = 参数_文本;
	TRegEvent* evt = GetRegEvent(L"OnValueChange");
	if (evt != 0) {
		evt->handler<int>(取窗口句柄(), 参数_项目句柄, 1);
	}
	int index = _GetItemIndex(参数_项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}
bool BlackMoonUI::zyPropertyGrid::置项目值_列表(PropertyGrid_item* 参数_项目句柄, int 参数_索引) {//项目赋值
	if (参数_项目句柄 == 0) {
		return false;
	}
	int type = 参数_项目句柄->Type;
	if (type != 属性类型_列表 && type != 属性类型_逻辑) {
		return false;
	}
	参数_项目句柄->currentIndex = 参数_索引;
	TRegEvent *evt = GetRegEvent(L"OnValueChange");
	if (evt != 0) {
		evt->handler<int>(evt, 取窗口句柄(), 参数_项目句柄, 1);
	}
	int index = _GetItemIndex(参数_项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}
bool BlackMoonUI::zyPropertyGrid::置项目值_逻辑(PropertyGrid_item* 参数_项目句柄, int 参数_逻辑值) {//项目赋值
	if (参数_项目句柄 == 0) {
		return false;
	}
	int type = 参数_项目句柄->Type;
	if (type != 属性类型_逻辑) {
		return false;
	}
	//参数_项目句柄->Value = std::to_wstring(参数_逻辑值);
    参数_项目句柄->currentIndex = 参数_逻辑值;
	TRegEvent* evt = GetRegEvent(L"OnValueChange");
	if (evt != 0) {
		evt->handler<int>(evt, 取窗口句柄(), 参数_项目句柄, 1);
	}
	int index = _GetItemIndex(参数_项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}
// 设置标志位属性值
bool BlackMoonUI::zyPropertyGrid::置项目值_标志位(PropertyGrid_item* 参数_项目句柄, int 参数_标志值)
{
	if (!参数_项目句柄 || 参数_项目句柄->Type != 属性类型_标志位)
		return false;

	// 更新当前标志值
	参数_项目句柄->Value = std::to_wstring(参数_标志值);

	// 触发值变更事件
	TRegEvent* evt = GetRegEvent(L"OnValueChange");
	if (evt) {
		evt->handler<int>(取窗口句柄(), 参数_项目句柄, 1);
	}

	// 更新显示
	int index = _GetItemIndex(参数_项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}
// 设置颜色属性值
bool BlackMoonUI::zyPropertyGrid::置项目值_颜色(PropertyGrid_item* 参数_项目句柄, int 参数_颜色值)
{
	if (!参数_项目句柄 || 参数_项目句柄->Type != 属性类型_颜色)
		return false;

	// 确保颜色值在有效范围
	参数_项目句柄->currentIndex = 参数_颜色值 & 0x00FFFFFF;

	// 触发变更事件
	TRegEvent* evt = GetRegEvent(L"OnValueChange");
	if (evt) {
		evt->handler<int>(取窗口句柄(), 参数_项目句柄, 1);
	}

	// 刷新显示
	int index = _GetItemIndex(参数_项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}
// 设置字体属性值
bool BlackMoonUI::zyPropertyGrid::置项目值_字体(PropertyGrid_item* 参数_项目句柄, const std::wstring& 参数_字体信息)
{
	if (!参数_项目句柄 || 参数_项目句柄->Type != 属性类型_字体)
		return false;

	// 格式示例："Arial,12"
	if (参数_字体信息.find(L',') == std::wstring::npos)
		return false;

	// 更新字体信息
	参数_项目句柄->Value = 参数_字体信息;

	// 触发事件
	TRegEvent* evt = GetRegEvent(L"OnValueChange");
	if (evt) {
		evt->handler<int>(取窗口句柄(), 参数_项目句柄, 1);
	}

	// 重绘项目
	int index = _GetItemIndex(参数_项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return true;
}


std::wstring BlackMoonUI::zyPropertyGrid::取项目值_文本(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == nullptr) {
		return L"";
	}
	int type = 参数_项目句柄->Type;
	if (type != 属性类型_文本 && type != 属性类型_长文本 && type != 属性类型_图片) {
		return L"";
	}
	return 参数_项目句柄->Value;
}
// 获取列表属性当前选中值
int BlackMoonUI::zyPropertyGrid::取项目值_列表(PropertyGrid_item* 参数_项目句柄)
{
	if (!参数_项目句柄 || 参数_项目句柄->Type != 属性类型_列表)
		return -1;

	// 返回当前选中的索引值
	return 参数_项目句柄->currentIndex;
}
int BlackMoonUI::zyPropertyGrid::取项目值_逻辑(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == nullptr) {
		return -1;
	}
	int type = 参数_项目句柄->Type;
	if (type != 属性类型_列表 && type != 属性类型_逻辑) {
		return -1;
	}
	return 参数_项目句柄->currentIndex;
}
// 获取标志位属性组合值
int BlackMoonUI::zyPropertyGrid::取项目值_标志位(PropertyGrid_item* 参数_项目句柄)
{
	if (!参数_项目句柄 || 参数_项目句柄->Type != 属性类型_标志位)
		return 0;

	// 返回组合后的标志位数值
	return _wtoi(参数_项目句柄->Value.c_str());
}
int BlackMoonUI::zyPropertyGrid::取项目值_颜色(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == nullptr) {
		return -1;
	}
	int type = 参数_项目句柄->Type;
	if (type != 属性类型_颜色) {
		return -1;
	}
	return 参数_项目句柄->currentIndex;
}
// 获取字体属性字符串
std::wstring BlackMoonUI::zyPropertyGrid::取项目值_字体(PropertyGrid_item* 参数_项目句柄)
{
	if (!参数_项目句柄 || 参数_项目句柄->Type != 属性类型_字体)
		return L"";

	// 返回格式化的字体信息字符串
	return 参数_项目句柄->Value;
}

std::wstring BlackMoonUI::zyPropertyGrid::取项目名(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == nullptr) {
		return L"";
	}
	return 参数_项目句柄->Name;
}
int BlackMoonUI::zyPropertyGrid::取项目类型(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == nullptr) {
		return 属性类型_未知;
	}
	return 参数_项目句柄->Type;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::取父项目(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == nullptr) {
		return 0;
	}
	return 参数_项目句柄->Parent;
}
int BlackMoonUI::zyPropertyGrid::取项目层次(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == nullptr) {
		return 0;
	}
	return 参数_项目句柄->Level;
}
int BlackMoonUI::zyPropertyGrid::取项目文本色(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == nullptr) {
		return 0;
	}
	return 参数_项目句柄->TextColor;
}
int BlackMoonUI::zyPropertyGrid::置项目文本色(PropertyGrid_item* 参数_项目句柄, int 参数_文本色) {
	if (参数_项目句柄 == nullptr) {
		return 0;
	}
	int oldColor = 参数_项目句柄->TextColor;
	参数_项目句柄->TextColor = 参数_文本色;
	int index = _GetItemIndex(参数_项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
	return oldColor;
}
LPARAM BlackMoonUI::zyPropertyGrid::取项目数值(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == nullptr) {
		return 0;
	}
	return 参数_项目句柄->userData;
}
bool BlackMoonUI::zyPropertyGrid::置项目数值(PropertyGrid_item* 参数_项目句柄, LPARAM 参数_数值) {
	if (参数_项目句柄 == nullptr) {
		return false;
	}
	参数_项目句柄->userData = 参数_数值;
	return true;
}
int BlackMoonUI::zyPropertyGrid::取项目状态(PropertyGrid_item* 参数_项目句柄) {//返回"属性状态_"开头常量
	if (参数_项目句柄 == nullptr) {
		return 0;
	}
	return 参数_项目句柄->State;
}
int BlackMoonUI::zyPropertyGrid::置项目状态(PropertyGrid_item* 参数_项目句柄, int 参数_状态) {
	LVFINDINFO lvfi = {0};
	if (参数_项目句柄 == nullptr) {
		return 0;
	}
	int oldState = 参数_项目句柄->State;
	if ((oldState & 1) == (参数_状态 & 1)){
		return oldState;
	}
	lvfi.flags = LVFI_PARAM;
	lvfi.lParam = (LPARAM)参数_项目句柄;
	int index = (int)发送消息(LVM_FINDITEMW, -1, (LPARAM)&lvfi);
	if (index == -1) {
		return oldState;
	}
	zyPropretyGrid_ExpandChange(参数_项目句柄, index);
	return oldState;
}
void BlackMoonUI::zyPropertyGrid::置项目只读(PropertyGrid_item* 参数_项目句柄, bool 参数_是否只读) {
	if (参数_项目句柄 == nullptr) {
		return ;
	}
	int state = 参数_项目句柄->State;
	if (参数_是否只读) {
		state = state | 属性状态_只读;
	}
	else {
		state = state & (~属性状态_只读);
	}
	参数_项目句柄->State = state;
}
bool BlackMoonUI::zyPropertyGrid::取项目只读(PropertyGrid_item* 参数_项目句柄) {
	int state = 参数_项目句柄->State;
	return (state & 属性状态_只读) != 0;
}
void BlackMoonUI::zyPropertyGrid::置项目只读仅编辑框(PropertyGrid_item* 参数_项目句柄, bool 参数_是否只读) {
	if (参数_项目句柄 == nullptr) {
		return;
	}
	int state = 参数_项目句柄->State;
	if (参数_是否只读) {
		state = state | 属性状态_只读仅编辑框;
	}
	else {
		state = state & (~属性状态_只读仅编辑框);
	}
	参数_项目句柄->State = state;
}
bool BlackMoonUI::zyPropertyGrid::取项目只读仅编辑框(PropertyGrid_item* 参数_项目句柄) {
	int state = 参数_项目句柄->State;
	return (state & 属性状态_只读仅编辑框) != 0;
}
int BlackMoonUI::zyPropertyGrid::取所有子项目(PropertyGrid_item* 参数_项目句柄, std::vector<PropertyGrid_item*>& 参数_子项目句柄) {//返回项目数
	std::vector<PropertyGrid_item*>* childs = nullptr;
	int count =0;
	参数_子项目句柄.clear();
	if (参数_项目句柄 == nullptr) {
		childs = (std::vector<PropertyGrid_item*>*)GetMember(L"Propertys");
	}
	else {
		childs = 参数_项目句柄->Childs;
	}
	if (childs != nullptr) {
		count = (int)childs->size();
	}
	return count;
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::取子项目(PropertyGrid_item* 参数_项目句柄, int 参数_索引) {//返回项目句柄
	std::vector<PropertyGrid_item*>* childs = nullptr;
	if (参数_项目句柄 == nullptr) {
		childs = (std::vector<PropertyGrid_item*>*)GetMember(L"Propertys");
	}
	else {
		childs = 参数_项目句柄->Childs;
	}
	if (childs == nullptr) {
		return 0;
	}
	return (*childs)[参数_索引];
}
int BlackMoonUI::zyPropertyGrid::取子项目数(PropertyGrid_item* 参数_项目句柄) {
	std::vector<PropertyGrid_item*>* childs = nullptr;
	int count=0;
	if (参数_项目句柄 == nullptr) {
		childs = (std::vector<PropertyGrid_item*>*)GetMember(L"Propertys");
	}
	else {
		childs = 参数_项目句柄->Childs;
	}
	if (childs != nullptr) {
		count = (int)childs->size();
	}
	return count;
}
int BlackMoonUI::zyPropertyGrid::取现行选中项目() {
	LVITEM item = {0};
	int index = (int)发送消息(LVM_GETNEXTITEM, -1, LVNI_SELECTED);
	if (index == -1) {
		return 0;
	}
	item.mask = LVIF_PARAM;
	item.iItem = index;
	发送消息(LVM_GETITEMW, 0, (LPARAM)&item);
	return (int)item.lParam;
}
bool BlackMoonUI::zyPropertyGrid::置现行选中项目(PropertyGrid_item* 参数_项目句柄) {
	LVITEM item = {0};
	int index = _GetItemIndex(参数_项目句柄);
	发送消息(LVM_SETSELECTIONMARK, 0, index);
	item.mask = LVIF_STATE;
	item.iItem = index;
	item.state = index == -1 ? ~LVIS_SELECTED : LVIS_SELECTED;
	item.stateMask = LVIS_SELECTED;
	return 发送消息(LVM_SETITEMSTATE, index, (LPARAM)&item) != 0;
}
bool BlackMoonUI::zyPropertyGrid::是否有子项目(PropertyGrid_item* 参数_项目句柄) {
	if (参数_项目句柄 == 0) {
		return false;
	}
	std::vector<PropertyGrid_item*>* childs = 参数_项目句柄->Childs;
	if (childs == 0) {
		return false;
	}
	return childs->size() != 0;
}
void BlackMoonUI::zyPropertyGrid::重画项目(PropertyGrid_item* 参数_项目句柄) {
	int index = _GetItemIndex(参数_项目句柄);
	if (index != -1) {
		发送消息(LVM_REDRAWITEMS, index, index);
	}
}
bool BlackMoonUI::zyPropertyGrid::置属性名列宽(int 参数_宽度) {
	if (参数_宽度 < 50) {
		return false;
	}
	HWND hWnd = 取窗口句柄();
	int ret = (int)发送消息(LVM_SETCOLUMNWIDTH, 0, 参数_宽度);
	RECT rc = {0};
	GetClientRect(hWnd, &rc);
	int valueWidth = rc.right - rc.left - 参数_宽度;
	SendMessage(hWnd, LVM_SETCOLUMNWIDTH, 0, 参数_宽度);
	SendMessage(hWnd, LVM_SETCOLUMNWIDTH, 1, valueWidth);
	return ret != 0;
}
int BlackMoonUI::zyPropertyGrid::取属性名列宽() {
	return (int)发送消息(LVM_GETCOLUMNWIDTH, 0, 0);
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::寻找项目(PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_项目名称) {
	return 寻找项目过程(参数_父项目句柄, 参数_项目名称);
}
BlackMoonUI::PropertyGrid_item* BlackMoonUI::zyPropertyGrid::寻找项目过程(PropertyGrid_item* 参数_父项目, const std::wstring& 参数_项目名称) {
	std::vector<PropertyGrid_item*>* childs = nullptr;
	PropertyGrid_item* item = nullptr;
	if (参数_父项目 == nullptr) {
		childs = (std::vector<PropertyGrid_item*>*)GetMember(L"Propertys");
	}
	else {
		childs = 参数_父项目->Childs;
	}
	if (childs == nullptr) {
		return 0;
	}
	std::wstring pFindName = 参数_项目名称;
	int count = (int)childs->size();
	for (int i = 0; i < count; i++) {
		item = (*childs)[i];
		if (item != 0) {
			std::wstring pName = item->Name;
			// 输出调试文本 (zyW2A_Point (pName));
			if (lstrcmp(pName.c_str(), pFindName.c_str()) == 0) {
				return item;
			}
			item = 寻找项目过程(item, 参数_项目名称);
			if (item != 0) {
				return item;
			}
		}
	}
	return 0;
}


void BlackMoonUI::zyPropertyGrid::触发属性值被改变事件(PropertyGrid_item* 参数_项目句柄) {
	TRegEvent* evt = GetRegEvent(L"OnValueChange");
	if (evt != 0) {
		evt->handler<int>(取窗口句柄(), 参数_项目句柄, 0);
	}
}
void BlackMoonUI::zyPropertyGrid::事件_属性值被改变(TRegEvent* 参数_事件指针) {
	SetRegEvent(L"OnValueChange", 参数_事件指针);
}
void BlackMoonUI::zyPropertyGrid::事件_项目被点击(TRegEvent* 参数_事件指针) {
	SetRegEvent(L"OnClick", 参数_事件指针);
}
void BlackMoonUI::zyPropertyGrid::事件_将进入编辑(TRegEvent* 参数_事件指针) {
	SetRegEvent(L"OnBeginEdit", 参数_事件指针);
}
void BlackMoonUI::zyPropertyGrid::事件_当前项目被改变(TRegEvent* 参数_事件指针) {
	SetRegEvent(L"OnItemChange", 参数_事件指针);
}
void BlackMoonUI::zyPropertyGrid::事件_双击项目(TRegEvent* 参数_事件指针) {
	SetRegEvent(L"OnDBClick", 参数_事件指针);
}